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
Solved

set the palette of TImage

Posted on 2000-02-28
6
396 Views
Last Modified: 2006-11-17
if I had a component
TImage Image1;
I want set it's palette,
How can I do this?
0
Comment
Question by:mathematics
  • 3
  • 2
6 Comments
 

Author Comment

by:mathematics
ID: 2567406
for exnape PALETTEENTRY *pe[16] =
{{255,255,255,0},{{0,0,0,0},...
}.............
and then?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2567910
hi mathematics,

a sample from the borland help
(based on a TBitmap)

unit bmpformu;

//
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TBmpForm = class(TForm)
    Button1: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Bitmap: TBitmap;
    procedure ScrambleBitmap;

    procedure WMEraseBkgnd(var m: TWMEraseBkgnd); message WM_ERASEBKGND;
  public
    { Public declarations }
  end;
var
  BmpForm: TBmpForm;
implementation

{$R *.DFM}

procedure TBmpForm.FormCreate(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('bor6.bmp');
end;
procedure TBmpForm.FormDestroy(Sender: TObject);
begin
  Bitmap.Free;
end;
// since we're going to be painting the whole form, handling this

// message will suppress the uneccessary repainting of the background
// which can result in flicker.
procedure TBmpform.WMEraseBkgnd(var m : TWMEraseBkgnd);
begin
  m.Result := LRESULT(False);
end;
procedure TBmpForm.FormPaint(Sender: TObject);
var
  x, y: Integer;
begin
  y := 0;
  while y < Height do
  begin
    x := 0;
    while x < Width do
    begin
      Canvas.Draw(x, y, Bitmap);

      x := x + Bitmap.Width;
    end;
    y := y + Bitmap.Height;
  end;
end;
procedure TBmpForm.Button1Click(Sender: TObject);
begin
  ScrambleBitmap;
  Invalidate;
end;

//
// scrambling the bitmap is easy when it has 256 colors:
// we just need to change each of the colors in the palette
// to some other value.
//
procedure TBmpForm.ScrambleBitmap;
var
  pal: PLogPalette;
  hpal: HPALETTE;

  i: Integer;
begin
  pal := nil;
  try
    GetMem(pal, sizeof(TLogPalette) + sizeof(TPaletteEntry) * 255);
    pal.palVersion := $300;
    pal.palNumEntries := 256;
    for i := 0 to 255 do
    begin
      pal.palPalEntry[i].peRed := Random(255);
      pal.palPalEntry[i].peGreen := Random(255);
      pal.palPalEntry[i].peBlue := Random(255);
    end;
    hpal := CreatePalette(pal^);
    if hpal <> 0 then

      Bitmap.Palette := hpal;
  finally
    FreeMem(pal);
  end;
end;
end.

meikl
0
 

Author Comment

by:mathematics
ID: 2571028
Can we not loadfromfile and
it's run ok?
->Bitmap.LoadFromFile('bor6.bmp');
Is this line necessary?
Because I didn't want use any resource.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2571444
hi mathematics,

thats just a sample,
which shows how to access a palette,
based on a bitmap, you must not load it from a file.

meikl
0
 

Author Comment

by:mathematics
ID: 2594118
After I Image1->Canvas->LineTo(100,100),
the palette is truecolor,
I set the palette to 16 colors,
and savetofile(a.bmp)
,I dump the a.bmp,
but the file is not 16 colors.
Why?
How can I setup the palette?
0
 
LVL 6

Accepted Solution

by:
edey earned 40 total points
ID: 2705020
you would need to set the TImage.picture.bitmap's pixelFormat property to pf16bit


GL
Mike
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 112
Intraweb download file link ? 1 155
Controlled Assessment GCSE - desperate help needed 4 102
RESTRequest Parameter 4 43
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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