Solved

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

Posted on 1997-04-30
2
966 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
ID: 1397051
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
ID: 1397052
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

896 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

13 Experts available now in Live!

Get 1:1 Help Now