Board index » delphi » How to create 16-color bitmap

How to create 16-color bitmap

Hi,

Does anyone know how to create a 16 (windows)color or 4-bit bitmap or
TCanvas? Finally, the graphic will be pasted in a lot of (word)documents. I
Have to reduce the size and actually I need only 3 colors. At the moment I
use 16-bit but the documents becomes to big and a bit slow...

Regards,

Yves V.

 

Re:How to create 16-color bitmap


this code create a new bitmap using the canvas content of  one TPanel. That
is, capture the panel canvas and create a new bitmap. With pixelformat, I
change the color depth (by default is stored to mismatch the current windows
config)
----------------------------------------------------------------------------
------------
procedure TfmtrabajosproductosED.btaceptarClick(Sender: TObject);
type
 LogPal = record
  lpal : TLogPalette;
  dummy:Array[0..255] of TPalet{*word*249}try;
    end;
var
 stream:Tstream;
 Source: TComponent;
 SysPal : LogPal;
 tempCanvas: TCanvas;
 sourceRect, destRect: TRect;
 image2save: TImage;
 notUsed: HWND;
    p,q: tpoint;
begin
 // guardar la informacion grafica del esquema bucal
 Source := FindComponent('panel');
 tempCanvas := TCanvas.Create;
 try
  with Source as TControl do
     tempCanvas.Handle := GetDeviceContext(notUsed);
     image2save:=TImage.create(self);
     try
      with image2save do begin
    Height := (Source as TControl).Height;
    Width :=  (Source as TControl).Width;
          destRect := Rect(0,0,Width,Height);

             p.x:=(Source as TControl).left;
                p.y:=(Source as TControl).top;
    q:=self.screentoclient((Source as TControl).parent.clienttoscreen(p));
    sourceRect :=rect(q.x,q.y,q.x+(Source as TControl).width,q.y+(Source as
TControl).height);

       Canvas.CopyRect(destRect,tempCanvas,sourceRect);
          SysPal.lPal.palVersion:=$300;
          SysPal.lPal.palNumEntries:=256;

GetSystemPalet{*word*249}tries(tempCanvas.Handle,0,256,SysPal.lpal.PalpalEntry);
          Picture.Bitmap.Palette:= CreatePalette(Syspal.lpal);
        end;
         image2save.picture.bitmap.pixelformat:=pf4bit;
   dbimage.picture.assign(image2save.picture);
  finally
      image2save.Free;
     end;
    finally
     tempCanvas.Free;
 end;
end;
----------------------------------------------------------------------------
-------------
if you only want to change the bitmap colordepth, you can transform into the
new using the pixelformat property

jul...@aleira.com

PD. Sorry for my poor english ... This code is a modified  delphi example
that I found in delphi help file ... but I not remember the topic ...

"Yves Vermeersch" <y...@cbt.nl> escribi en el mensaje
news:3b0e4138$0$34248@news2.zeelandnet.nl...

Quote
> Hi,

> Does anyone know how to create a 16 (windows)color or 4-bit bitmap or
> TCanvas? Finally, the graphic will be pasted in a lot of (word)documents.
I
> Have to reduce the size and actually I need only 3 colors. At the moment I
> use 16-bit but the documents becomes to big and a bit slow...

> Regards,

> Yves V.

Other Threads