ImageEn, unit iexBitmaps

TIEBitmap.EncapsulateMemory

TIEBitmap.EncapsulateMemory

Declaration

procedure EncapsulateMemory(mem: Pointer; bmpWidth, bmpHeight: Integer; bmpPixelFormat: TIEPixelFormat; DoFreeImage: Boolean; Origin: TIEBitmapOrigin = ieboBottomLeft);

Description

Encapsulates an existing bitmap from its buffer.
It is useful to pass a raw buffer to routines that require a TIEBitmap.
The buffer is not owned by TIEBitmap (it is not freed on destroy).
If DoFreeImage is True, any previous image content held by this TIEBitmap is freed before encapsulating the buffer.
Origin specifies the image orientation (default is bottom-left, that is Windows default. For example set ieboTopLeft with OpenCV images).

Example

GetMem( buf, width * height * 3 );
try
  // ... fill buf with BGR pixels ...
  bmp := TIEBitmap.Create();
  try
    bmp.EncapsulateMemory( buf, width, height, ie24RGB, False );
    bmp.Proc.Negative();
    // changes are written into buf
  finally
    FreeAndNil( bmp );  // does not free buf
  end;
finally
  FreeMem( buf );
end;