Solved

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

Posted on 2015-01-22
1
1,160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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…

733 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