Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1997-04-30
2
Medium Priority
?
1,062 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
[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
2 Comments
 

Accepted Solution

by:
jnewlin earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

610 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