Solved

Realizing Palettes

Posted on 1997-09-17
3
891 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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
mirek071497 earned 60 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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