Solved

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

Posted on 1997-04-30
2
991 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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 …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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