Solved

How do I convert 24bpp bitmap images to 32bpp color and 16 bpp grayscale bitmap images?

Posted on 2015-01-22
1
1,092 Views
Last Modified: 2015-01-22
Hi:

I've got an app that does bitmap analysis.
Currently we've been working against 24bpp bitmaps.

We need to test our code against 32bpp and 16bpp grayscale bitmaps.
We've got a bunch of 24bpp bitmaps as part of our test images.
Ideally, we'd like to use the same images but convert them to the desired
formats.

1) What is the best way to accomplish this?

2) Are there any drawing tools (either desktop or web based) which I could use?
    (This would be the preferred method.)

3) Our app is a 32 bit unmanaged windows app. It's written in C++ and utilizes the
openCV, boost and GDI+ libraries. How would I do this programmatically?
0
Comment
Question by:jxbma
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40564656
Gimp (http://www.gimp.org/) can do that, and it's GPL. Just use 'File|Export as...', select Windows Bitmap and choose the bit depth in the dialog that follows.

Regarding how to do that in code, I couldn't find an example on MSDN, but this discussion: https://social.msdn.microsoft.com/Forums/vstudio/en-US/08d03bbb-e535-4b53-a74e-3b021130fc82/gdiimage-how-to-change-pixelformat-to-pixelformat24bpprgb?forum=vcgeneral

Or, in short:
Image* image = new Image(L"temp.bmp"); // 24bit image

Bitmap *dest = new Bitmap(image->GetWidth(), image->GetHeight(), PixelFormat32bppRGB);

//create a graphics from the image
Graphics *g = Graphics::FromImage(dest);

//draw the 32bit per pixel image into the 32 bit per pixel image
g->DrawImage(image, Point(0, 0));

delete image; // source

//now save the 24 bit per pixel to disk
CLSID m_clsidGdiplusBmpEncoder;
GetEncoderClsid( L"image/bmp", &m_clsidGdiplusBmpEncoder );
dest->Save( L"temp2.bmp", &m_clsidGdiplusBmpEncoder, NULL );

delete dest;
delete g; 

Open in new window


(Source: Internet :-/)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question