?
Solved

Realizing Palettes

Posted on 1997-09-17
3
Medium Priority
?
895 Views
Last Modified: 2010-08-05
I load a bitmap from my users hard drive. I find that my user only has 256 colours available. So I need to realize a palette. So why doesn't:

//*******
PalPrev := SelectPalette(Canvas.Handle, MyBitmap.Palette, False);
r := RealizePalette(Canvas.Handle);
//show my picture here (with flashy effect!)
ShowPic(MyBitmap);
//afterwards, clean up:
SelectPalette(Canvas.Handle, PalPrev, True);
//********

work? (note, Canvas refers to the main form's canvas)

I tried changing the painting to a TPaintBox, but I got the same answer. Please also note that (for the form) I am intercepting the WM_ERASEBACKGROUND message, in order for my special effects to be flicker free. Surely that can't be the problem? Also, I know that MyBitmap has a palette.

I'll give anyone who can solve my problem a B, with an A reserved for those who give me a good explanation of why my above code doesn't work.
0
Comment
Question by:wolfcrag
[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
3 Comments
 
LVL 3

Accepted Solution

by:
mirek071497 earned 240 total points
ID: 1345308
1.The easiest way to draw you'r bitmap is in exchange of you'r more than 4 lines use only one :

Canvas.Draw( 0, 0, MyBitmap );

but mayby you can't use this (i don't know why).

2.You'r code can't work because of you'r call to Canvas.Handle is not good (delphi caching algorithm). You must use this as in this example :

var
  PalPrev : HPalette;
  NewDC : HDC;
  FormDC : HDC;
begin
  FormDC := GetDC( Handle );
  PalPrev := SelectPalette( FormDC, MyBitmap.Palette, False);
  RealizePalette( FormDC );
{ painting on FormDC }
  NewDC := CreateCompatibleDC( Canvas.Handle );
  SelectObject( NewDC, MyBitmap.Handle );
  BitBlt( FormDC, 0, 0, 100, 100, NewDC, 0, 0, SrcCopy );
{ end of Painting }
  DeleteDC( NewDC );
  SelectPalette( FormDC, PalPrev, True);
  ReleaseDC( Handle, FormDC );
end;

0
 
LVL 3

Author Comment

by:wolfcrag
ID: 1345309
Can you elaborate further on this delphi caching algorithm, and/or why calls to Canvas.Handle are not good? Your code worked beautifully. Thanks!
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1345310
My english is rather poor so i think that have no sense but the problem is in Delphi3 (if i good remember) and with Delphi2 all works fine. In Delphi3 Borland made some changes to palette and i don't work about it hard and i don't know how say this good. There are added methods for manipulating palette but i think so with some mistakes because sometimes i can't get acces to the palette.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 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