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.
// 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 );