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

x
?
Solved

Selecting a palette in 256 color mode

Posted on 1998-08-17
5
Medium Priority
?
329 Views
Last Modified: 2013-11-20
I have a bitmap which is drawn in a specific palette, and would like to draw this bitmap using that palette when my application is using 256 color mode.

I have created a bitmap resource, and used VC++'s resource editor's Load Palette dialog to load my palette. My bitmap looks fine in the resource editor's bitmap display. However, also in the resource editor, my bitmap is flattened to 16 color when I use the bitmap in a dialog resource.

My bitmap is also drawn in 16 colors when that dialog is displayed by my application.

What I have tried:
Please do not answer this question, suggesting that I try any of the following, since I already have.

I have a function that returns an HPALETTE, given a bitmap filename. I use this function to get the palette out of a palette.bmp file I intend to ship with my application. I have then tried calling SelectPalette and RealizePalette from the following callbacks:
  OnInitDialog, OnPaint, OnQueryNewPalette

None of these worked.

A friend told me that when calling LoadBitmap in 256 color mode, that windows automatically reduces the image to 16 colors, so the information is lost. He says the only way to draw the image in the 256 colors is to create the bitmap yourself and realize the palette in its DC, then draw it yourself into the dialog.

I think there must be a better way.

Can you give me an easy solution that will allow me to draw a bitmap into a dialog, using a specific palette that I have access to?

Thanks,
Brett Levine
bl@pobox.com
0
Comment
Question by:circuit
[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
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 400 total points
ID: 1320926
Your friend is right. LoadBitmap converts a DIB to a DDB. Thus, the palette information is lost. Use LoadImage instead and draw it yourself. You need to select and realize the palette in OnPaint, OnQueryNewPalette and OnPaletteChanged. You can find the example code at http://www.codeguru.com/bitmap/index.shtml.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320927
> A friend told me that when calling LoadBitmap in 256 color mode, that windows automatically reduces the image to 16 colors

Nah, I do it quite frequently.  Can we see your code?

Phillip

0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320928
If I remember right, and I have some code up at work, we use the FindResource/LoadResource to load the image as data, but not with the LoadImage function.  Chensu (and your friend with full apologies) is correct on that point.

I'll send the code tomorrow, but it's only a combination of those two functions. (Unless I'm overly mistaken (And I'm normally)).

Phillip
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320929
In 16-bit world, we used the FindResource/LoadResource. In Win32, we can use LoadImage to make life easier.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320930
You're absolutely right chensu, thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

660 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