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

x
?
Solved

Realizing Palettes

Posted on 1997-09-17
3
Medium Priority
?
896 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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