Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,440 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 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

704 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