TIEBitmap.SynchronizeRGBA
Declaration
procedure SynchronizeRGBA(RGBAtoAlpha: boolean; UpdatePixelFormat: Boolean = False);
Description
When ie32RGB (RGBA) pixel format is used, the A channel is not used. Alpha channel is stored in a separated plane (
AlphaChannel).
To copy from A channel to ImageEn Alpha channel, call SynchronizeRGBA( True ); If
UpdatePixelFormat is true, the
PixelFormat will be set to ie24RGB.
To copy from ImageEn Alpha channel to A channel, call SynchronizeRGBA( False ); If
UpdatePixelFormat is true, the
PixelFormat will be set to ie32RGB.
Note: Alternatively, you can use
AlphaLocation
// Assign a 32bit Bitmap with alpha channel to an ImageEnView (keeping the alpha)
var
bmp: TBitmap;
begin
bmp := TBitmap.Create();
bmp.LoadFromFile( 'Bmp32_with_Alpha.bmp' );
ImageEnView1.IEBitmap.Assign( bmp );
ImageEnView1.IEBitmap.SynchronizeRGBA( true );
ImageEnView1.Update();
bmp.Free();
end;
// Output content of TImageEnView as a 32bit Bitmap with alpha channel
var
bmp: TBitmap;
begin
bmp := TBitmap.Create();
ImageEnView1.IEBitmap.SynchronizeRGBA( False, True ); // Convert 24bit Image + Alpha channel to 32bit RGBA
ImageEnView1.IEBitmap.CopyToTBitmap( bmp );
... bmp is now 32bit
bmp.Free();
end;
// Copy TIEBitmap with Alpha to 32bit BMP
iebmp := TIEBitmap.Create();
bmp := TBitmap.Create();
iebmp.LoadFromFile( 'D:\OriginalAlpha.png' );
iebmp.SynchronizeRGBA(False, True); // Convert 24bit Image + Alpha channel to 32bit RGBA
iebmp.CopyToTBitmap( bmp );
... Do something with bitmap, e.g. bmp.SaveToFile( 'D:\BMP32.bmp' );
bmp.Free;
iebmp.Free;
// Copy 32bit BMP to TIEBitmap with Alpha
iebmp := TIEBitmap.Create();
bmp := TBitmap.Create();
... Get 32bit Bitmap, e.g. bmp.LoadFromFile('D:\BMP32.bmp');
iebmp.CopyFromTBitmap( bmp );
iebmp.SynchronizeRGBA(True, True); // Convert 32bit RGBA to 24bit Image + Alpha channel
iebmp.SaveToFile( 'D:\Alpha.png' );
bmp.Free;
iebmp.Free;
// Draw a semi-transparent ellipse
var
bitmap: TIEBitmap;
begin
bitmap := TIEBitmap.Create( 500, 500, ie32RGB ); // <= RGBA required!
bitmap.Fill( 0 );
bitmap.AlphaChannel.Fill( 0 );
bitmap.IECanvas.SetCompositingMode( ieCompositingModeSourceOver, ieCompositingQualityDefault );
bitmap.IECanvas.Pen.Width := 4;
bitmap.IECanvas.Pen.Color := clRed;
bitmap.IECanvas.Brush.Color := clBlue;
bitmap.IECanvas.Pen.Transparency := 90;
bitmap.IECanvas.Brush.Transparency := 90;
bitmap.IECanvas.Ellipse(10, 10, 400, 400);
bitmap.SynchronizeRGBA( True ); // <= gdi+ draws alpha on RGBA. This copies 'A' to TIEBitmap alpha channel
ImageEnView1.IEBitmap.Assign( bitmap );
ImageEnView1.Update();
bitmap.Free();
end;
// Display a layer containing an image with alpha transparency in a TImage
iebmp := TIEBitmap.Create();
iebmp.Assign( ImageEnView1.Layers[3].Bitmap );
iebmp.SynchronizeRGBA( False, True ); // Convert 24bit Image + Alpha channel to 32bit RGBA
iebmp.CopyToTBitmap( Image1.Picture.Bitmap );
Image1.Picture.Bitmap.AlphaFormat := afDefined; // Make TImage handle Alpha
iebmp.Free;
See Also
◼CopyToTBitmap
◼CopyFromTBitmap
◼AssignTo
◼SetCompositingMode
◼AlphaLocation