Solved

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

Posted on 2015-01-22
1
930 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now