Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-22
1
Medium Priority
?
1,560 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

782 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