Difference between revisions of "TBGRABitmap class"

From Lazarus wiki
Jump to navigationJump to search
(→‎Constructors: explicit instance)
(→‎Text fonctions: wiki text functions)
Line 109: Line 109:
 
   function TextSize(sUTF8: string): TSize;   
 
   function TextSize(sUTF8: string): TSize;   
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
See [[TBGRABitmap text functions]].
  
 
=== Pixel functions ===
 
=== Pixel functions ===

Revision as of 00:59, 24 March 2015

TBGRABitmap class contains an image stored in BGRA 32-bit format.

Format

Each pixel is a sequence of 4 bytes containing blue, green, red and alpha channel. One pixel is a TBGRAPixel record, defined as follows:

TBGRAPixel = packed record
  blue, green, red, alpha: byte;
end;

The following properties allow to access the data directly:

class TBGRABitmap
  property Width: integer;
  property Height: integer;
  property NbPixels: integer;
  property ScanLine[y: integer]: PBGRAPixel;
  property LineOrder: TRawImageLineOrder;
  property Data: PBGRAPixel;
  property Caption: string; read write;
  property Empty: boolean;
  property HasTransparentPixels: boolean;

Width and Height are the dimensions, in pixels, of the image. NbPixels is the total number of pixels. It is always true that NbPixels = Width * Height.

ScanLine returns the address of the left-most pixel of any line. The parameter ranges from 0 to Height-1.

LineOrder indicates the order in which lines are stored in memory. If it is equal to riloTopToBottom, the first line is the top line. If it is equal to riloBottomToTop, the first line is the bottom line.

Data provides a pointer to the first pixel in memory. Depending on the LineOrder property, this can be the top-left pixel or the bottom-left pixel. There is no padding between scanlines, so the start of the next line is at the address Data + Width.

Caption can contain a text to describe the image. It is not displayed.

Empty returns True if the bitmap only contains transparent pixels or has a size of zero.

HasTransparentPixels returns True if there are transparent or semitransparent pixels, and so if the image would be stored with an alpha channel.

See how to access pixels directly.

Constructors

  constructor TBGRABitmap.Create;

Creates an image of width and height equal to zero.

  procedure SetSize(AWidth, AHeight: integer);

Can only be called with an existing instance of TBGRABitmap. Sets the dimensions of an existing TBGRABitmap instance.

  constructor Create(AWidth, AHeight: integer);

Creates an image of dimensions AWidth and AHeight and filled with transparent pixels.

  constructor TBGRABitmap.Create(ABitmap: TBitmap);

Creates an image and copy the content from ABitmap.

  constructor TBGRABitmap.Create(AWidth, AHeight: integer; Color: TColor);

Creates an image of dimensions AWidth and AHeight and fills it with the opaque color Color.

  constructor TBGRABitmap.Create(AWidth, AHeight: integer; Color: TBGRAPixel);

Creates an image of dimensions AWidth and AHeight and fills it with Color.

  constructor TBGRABitmap.Create(AFilename: string);

Creates an image by loading its content from the file AFilename. The encoding of the string is the default one for the operating system. It is recommended to use the next constructor and UTF8 encoding.

  constructor TBGRABitmap.Create(AFilename: string; AIsUtf8Filename: boolean);

Creates an image by loading its content from the file AFilename. The boolean AIsUtf8Filename specifies if UTF8 encoding is assumed for the filename.

  constructor TBGRABitmap.Create(AStream: TStream);

Creates an image by loading its content from the stream AStream.

  function NewBitmap(AWidth, AHeight: integer): TBGRACustomBitmap;

Can only be called from an existing instance of TBGRABitmap. Creates a new instance with dimensions AWidth and AHeight, containing transparent pixels.

  function NewBitmap(AWidth, AHeight: integer; Color: TBGRAPixel): TBGRACustomBitmap;

Can only be called from an existing instance of TBGRABitmap. Creates a new instance with dimensions AWidth and AHeight, containing transparent pixels. You may need to change the return type to TBGRABitmap. For example:

var bmp1, bmp2: TBGRABitmap;
begin
  bmp1 := TBGRABitmap.Create(100,100);
  bmp2 := bmp1.NewBitmap(100,100);
  ...
end;
  function NewBitmap(Filename: string): TBGRACustomBitmap;

Can only be called from an existing instance of TBGRABitmap. Creates a new instance with by loading its content from the file Filename. The encoding of the string is the default one for the operating system.

See how to load and display an image.

Text fonctions

class TBGRABitmap
  property FontName: string;
  property FontStyle: TFontStyles;
  property FontQuality : TBGRAFontQuality;
  property FontOrientation: integer;
  property FontHeight: integer; read write;
  property FontAntialias: Boolean; read write;
  property FontFullHeight: integer; read write;
  property FontPixelMetric: TFontPixelMetric;
  property FontRenderer: TBGRACustomFontRenderer; read write;

  procedure TextOut(x, y: single; sUTF8: string; c: TBGRAPixel; align: TAlignment);
  procedure TextOut(x, y: single; sUTF8: string; texture: IBGRAScanner; align: TAlignment);
  procedure TextOutAngle(x, y: single; orientationTenthDegCCW: integer; sUTF8: string; c: TBGRAPixel; align: TAlignment);
  procedure TextOutAngle(x, y: single; orientationTenthDegCCW: integer; sUTF8: string; texture: IBGRAScanner; align: TAlignment);
  procedure TextOut(x, y: single; sUTF8: string; c: TBGRAPixel);
  procedure TextOut(x, y: single; sUTF8: string; c: TColor);
  procedure TextOut(x, y: single; sUTF8: string; texture: IBGRAScanner);
  procedure TextRect(ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; c: TBGRAPixel);
  procedure TextRect(ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; texture: IBGRAScanner);
  procedure TextRect(ARect: TRect; sUTF8: string; halign: TAlignment; valign: TTextLayout; c: TBGRAPixel);
  procedure TextRect(ARect: TRect; sUTF8: string; halign: TAlignment; valign: TTextLayout; texture: IBGRAScanner);
  function TextSize(sUTF8: string): TSize;

See TBGRABitmap text functions.

Pixel functions

class TBGRABitmap
  procedure SetPixel(x, y: int32or64; c: TColor);
  procedure XorPixel(x, y: int32or64; c: TBGRAPixel);
  procedure SetPixel(x, y: int32or64; c: TBGRAPixel);
  procedure DrawPixel(x, y: int32or64; c: TBGRAPixel);
  procedure DrawPixel(x, y: int32or64; c: TBGRAPixel; ADrawMode: TDrawMode);
  procedure DrawPixel(x, y: int32or64; ec: TExpandedPixel);
  procedure FastBlendPixel(x, y: int32or64; c: TBGRAPixel);
  procedure ErasePixel(x, y: int32or64; alpha: byte);
  procedure AlphaPixel(x, y: int32or64; alpha: byte);
  function GetPixel(x, y: int32or64): TBGRAPixel;
  function GetPixel256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter = rfLinear; smoothBorder: boolean = true): TBGRAPixel;
  function GetPixel(x, y: single; AResampleFilter: TResampleFilter = rfLinear; smoothBorder: boolean = true): TBGRAPixel;
  function GetPixelCycle(x, y: int32or64): TBGRAPixel;
  function GetPixelCycle(x, y: single; AResampleFilter: TResampleFilter = rfLinear): TBGRAPixel;
  function GetPixelCycle(x, y: single; AResampleFilter: TResampleFilter; repeatX: boolean; repeatY: boolean): TBGRAPixel;
  function GetPixelCycle256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter = rfLinear): TBGRAPixel;
  function GetPixelCycle256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter; repeatX: boolean; repeatY: boolean): TBGRAPixel;