Solved

Converting 65536/256-color bitmap to 16 colors under Win16

Posted on 1997-04-30
2
949 Views
Last Modified: 2013-12-04
Under Win16, I have a 65536-color or 256-color bitmap
(of size 32x32 because it's an icon's XOR mask) and I
want to convert it to a 16-color bitmap (I need to write
a 16-color XOR mask into a .ICO file). I am using Visual
C++ 1.52c under Windows 95/3.1.

What is the algorithm in C/C++ to do this?
0
Comment
Question by:sarrazip
2 Comments
 

Accepted Solution

by:
jnewlin earned 100 total points
Comment Utility
It depends on if you know what colors are available in the
16-bit image.  If you do, it's pretty easy.  If you don't
then you have to figure out how to choose the colors, which
can be pretty complex.

Assuming you know the color table for the 16-bit bitmap,
you can do something pretty simple, since the amount of
data that you are working with is small, you can do a linear
lookup on each pixel.  It's slow on large data, but should
be ok with a 32x32 bitmap.

All you do, is for each pixel in the original bitmap, get
a COLORREF that is the color of that pixel, then call
GetNearestColor(hdcOfDestBitMap, colorRef).
Then use the value that that returns as your the value for
the pixel that you are writing.  Of course you'll have to
have an HDC into the bitmap that you are writing.
0
 

Author Comment

by:sarrazip
Comment Utility
The original bitmap has 16-bit entries. I try to use
GetSystemPaletteEntries() to obtain a COLORREF
from a 16-bit entry, using the HDC returned by GetDC(),
but it fails.

Anyway, I have found a different method that involves
GetBitmapBits() and CreateBitmap() and no HDCs, assuming
that the goal is to produce a .ICO file.

Thanks.

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

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

12 Experts available now in Live!

Get 1:1 Help Now