Bitmaps unit


TBitmap Object

Methods


Clone

Declaration:

Function Clone:PBitmap;

Description:

Creates an exact copy of the bitmap.


GetData

Declaration:

Function GetData:pointer;

Description:

Returns a pointer to the image for use with PutImage.

Example:

   PutImage(0, 0, Bitmap.GetData^);

GetPalette

Declaration:

Function GetPalette:PPalette;

Description:

Returns a pointer to the palette of the image, the palette is an array of 256 longints. The result is nil if the bitmap contains no palette.

Bits Contents
0 - 7: Value for Blue color component
8 - 15: Value for Green color component
16 - 24: Value for Red color component
25 - 31: un-used

The layout of a palet entry.

Example:

   if Bitmap.HasPalette then
      setRGBPalette(Bitmap.GetPalette);

GetSize

Declaration:

Function GetSize:longint;

Description:

Returns the amount of memory allocated for the image. The amount of memory required for an image is calculated as follows: 4 + width * height * BytesPerPixel.


HasPalette

Declaration:

Function HasPalette:boolean;

Description:

Returns true if the bitmap contains a palette.

See also:

GetPalette


LoadFromFile

Declaration:

Function LoadFromFile(Filename: string):boolean;

Description:

LoadFromFile loads an image file, and returns true if succesfull.

Example:

  uses graph, bitmaps, bmp;

  var 
     Bitmap:TBitmap;
     GraphDriver, GraphMode: integer;

  begin
  GraphDriver := Detect;
  InitGraph(GraphDriver, GraphMode, '');
  Bitmap.Create;
  if Bitmap.LoadFromFile('bitmap.bmp') then begin
     PutImage((GetMaxX + 1 - Bitmap.getWidth) shr 1,
     (GetMaxY + 1 - Bitmap.getHeight) shr 1,
     Bitmap.getData^);
     end ;
  Bitmap.Destroy;
  CloseGraph;
  end .


SetWidth

Declaration:

Procedure SetWidth(value: word);

Description:

Sets the width of the image to value.


SetHeight

Declaration:

Procedure SetHeight(value: word);

Description:

Sets the height of the image to value.


ScaleTo

Declaration:

procedure ScaleTo(AWidth, AHeight: word);

Description:

Scales the image.

Example:

   Bitmap.ScaleTo(Bitmap.GetWidth*2, Bitmap.GetHeight*2);

SetBytesPerPixel

Declaration:

Procedure SetBytesPerPixel(value: word);

Description:

Sets the number of bytes required per pixel. This value should match the number of bytes per pixel of the current video mode. Possible values are: 1 for 8 bit modes, 2 for 15/16 bit modes and 4 for 24/32 bit modes.

Example:

   Bitmap.setBytesPerPixel(2);

 

Gertjan Schouten
June 09, 1998