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

x
?
Solved

Paletteindex() relates to RGB() as...

Posted on 1997-09-14
11
Medium Priority
?
561 Views
Last Modified: 2010-04-04

My question is: can some give the code for a procedure
BLA (Paletteindex: word; var Red,Green,Blue: word/integer?)

such that Shape1 will give the same color as Shape2

Shape1.Brush.Color:=paletteindex(x);

yields the same as

BLA(PaletteIndex(x), Red,GReen,Blue);
Shape2.Brush.Color:=RGB(Red,Green,Blue);
0
Comment
Question by:yonasb
[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
  • 7
  • 4
11 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344800
You'r have problem because each control can have different palette and when you type
Shape1.Brush.Color := paletteindex(n) then you specify number in logical palette but when you type
Shape1.Brush.Color := RGB( ....) then windows calculate which entry of this paleete need to use.

I don't fully understand your question. Do you need read RGB values for PaletteEntry which have Index=n ?
If this is true you need to use GetPaletteEntries which retrive palette RGB values.
0
 

Author Comment

by:yonasb
ID: 1344801
To Mirek:

I know :
UINT GetPaletteEntries(
    HPALETTE  hpal,UINT  iStartIndex,      
    UINT  nEntries,    LPPALETTEENTRY  lppe );

-> But I do not understand how to use it.

I want the code for the following procedure.

Procedure GetRGBFromCurrentPalette
        (index: integer;
         var Red,Green,Blue: integer);
begin
??? <-can someone write this
end.

Example:

Shape1.Brush.Color:=PaletteIndex(12);

GetRGBFromCurrentPalette(12,Red,Green,Blue);

Shape2.Brush.Color:=RGB(Red,Green,Blue).

Shape1 en Shape2 must give the same color ON THE SCREEN.


Can you or someone else please write this little procedure for me?

Thanks
Yonas
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344802
Retrive RGB for palette - no problem, but you don't know palette  for tshape ! I think so you try make pogram with wrong way. Tell me what you are doing and i try help you more.

procedure GetRGBFromPalette( Hpal : HPalette; index : integer; var R,G,B : integer );
var lppe : TPaletteEntry;
begin
  if HPal<>0 then
  begin
    GetPaletteEntries ( HPal, index, 1, lppe );
    r:= lppe.peRed;
    g:= lppe.peGreen;
    b:= lppe.peBlue;
  end
  else
    ShowMessage( 'no palette' );
end;

p.s. When you Set color from PaletteIndex then you can't retrive values for R,G,B without Handle to palette.  VCL playing with this handle but you can't get acces to  this handle. This is because TShape is only for simple shape if you need more you need use own component as descendant of TGraphicControl.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:mirek071497
ID: 1344803
Do you understand my comment?
Do you need more help ?
0
 

Author Comment

by:yonasb
ID: 1344804
Mirek,

I don't understand. I need more help.

Do you mean this: ?????

I can set  Shape1.Brush.Color := $01000001
When I do, the color of Shape1.Brush.Color becomes
palette color 1 in Windows palette (if that is the
current palette).
You say: I cannot get the RGB value because I don't have
a handle to the palette.
?????????


How can I read the color of Shape1.Brush??

I must be able to use $010000xx because I want to read
the current palette color of Windows. In my program some
shapes must have the same color and when my program is running
and I change the colorscheme in Windows, I want to see
the new colors in my program.

I also must be able to calculate the difference between
two color.

You understand?
Example:
I have DynShape[1].Brush.Color:= $01000001, RGB=R1,G1,B1
I have DynShape[10].Brush.Color:=$01000011, RGB=R10,G10,B10

I calculate Rdelta:= (R10-R1) div (10 -9)
   {  Gdelta, Bdelta  same way}

Then I say, DynShape[2..9] you get the colors in between:

for x:=2 to 9
  DynShape[x].Brush.Color:=RGB(R1 + (x-1)*Rdelta,
                               G1  + (x-1) *Gdelta,
                               B1  + (x-1) * Bdelta).

Do you understand what I want Mirek?

I increase the points (only to 70, I don't have more).





 






0
 

Author Comment

by:yonasb
ID: 1344805
Adjusted points to 70
0
 

Author Comment

by:yonasb
ID: 1344806
Edited text of question
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344807
I think so now I know what you need, and as i say later you do this in bad way. If you set color as $01.... then you don't use system palette but current realized plette for control. You can read system palette entries with GetPaletteEntries (winapi) and then set color as $00BBGGRR where BB is blue GG is green RR is red. This can be done in TShape without limitation.

I post here example after some hours.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 80 total points
ID: 1344808
1.Change of color scheme don't change system palette! If you need use colors from Color scheme then you must usee constans defined in Graphics.Pas

clScrollBar = TColor(COLOR_SCROLLBAR or $80000000);
  clBackground = TColor(COLOR_BACKGROUND or $80000000);
  clActiveCaption = TColor(COLOR_ACTIVECAPTION or $80000000);
  clInactiveCaption = TColor(COLOR_INACTIVECAPTION or $80000000);
  clMenu = TColor(COLOR_MENU or $80000000);
and many other

2.If you need read system palette and use then this is example :

procedure TForm1.Button1Click(Sender: TObject);
var
  lk : integer;
  r,g,b : byte;

  function GetPalColor( nr : integer; var r,g,b : byte ) : TColor;
  var
    PalEntries : array[0..255] of TPaletteEntry;
    HowMany    : integer;
    l : longint;
    DC : HDC;
  begin
    DC := GetDC( Handle );  { retrive DC for form, it can be any valid DC }
    HowMany := GetSystemPaletteEntries( DC, 0, 255, PalEntries );
    ReleaseDC( Handle, DC );
    if nr>HowMany then
      ShowMessage( 'Palette have only '+IntToSTr(HowMany)+' entries' );
    l := PalEntries[nr].peBlue;
    l := l*256+PalEntries[nr].peGreen;
    l := l*256+PalEntries[nr].peRed;
    result := l;
    r := PalEntries[nr].peRed;
    g := PalEntries[nr].peGreen;
    b := PalEntries[nr].peBlue;
  end;

begin
  lk := 5;
  Shape1.Brush.Color := GetPalColor(lk,r,g,b);
  Shape2.Brush.Color := RGB( r,g,b );
end;

Do you need more ? Ask !
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344809
Hi
Are you there ?
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344810
Do you understand the colors ?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

597 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