If you want to use a png with a VCL component and not use ImageEn to view the png image then you must use Vcl.Imaging.PngImage then assign the TPngImage to the TImage.Picture. With out knowing which component you are using to load the bitmap it is difficult to answer your question directly, but I think the problem you may be having is loading the png image into the vcl component after you convert it. What VCL component are you using to load or view the bitmap?
Here is a sample that loads a bitmap into Image1, converts the bitmap to a PngImage, then assigns the PngImage to Image2. To compile this create a new VCL project, add a TPanel to the form and add 2 buttons named Open1 and Convert1 to the TPanel, then add two TImage components to the form. Set both TImage components Transparency property to true. Then add this code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ExtDlgs, Vcl.Imaging.PngImage,
imageenio, imageenproc, iexbitmaps, hyiedefs, hyieutils;
type
TForm1 = class(TForm)
Panel1: TPanel;
Open1: TButton;
Convert1: TButton;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Image2: TImage;
procedure Convert1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Convert1Click(Sender: TObject);
var
iBitmap: TBitmap;
iRGB: TRGB;
iImageEnIO: TImageEnIO;
iBMPStream: TMemoryStream;
iImageEnProc: TImageEnProc;
iOutputStream: TMemoryStream;
iPngImage: TPngImage;
begin
iImageEnIO := TImageEnIO.Create(nil);
try
iBMPStream := TMemoryStream.Create;
try
iImageEnProc := TImageEnProc.Create(nil);
try
iBitmap := TBitmap.Create;
try
iBitmap.Assign(Image1.Picture.Bitmap);
iBitmap.SaveToStream(iBMPStream);
iBMPStream.Position := 0;
iImageEnIO.LoadFromStreamBMP(iBMPStream);
iImageEnIO.Params.BMP_HandleTransparency := True;
iImageEnProc.AttachedIEBitmap := iImageEnIO.IEBitmap;
iRGB := iImageEnIO.IEBitmap.Pixels[0, iImageEnIO.IEBitmap.Height-1];
iImageEnProc.SetTransparentColors(iRGB,iRGB);
iOutputStream := TMemoryStream.Create;
try
iImageEnIO.SaveToStreamPNG(iOutputStream);
iOutputStream.Position := 0;
iPngImage := TPngImage.Create;
try
iPngImage.LoadFromStream(iOutputStream);
Image2.Picture.Assign(iPngImage);
Image2.Update;
finally
iPngImage.Free;
end;
finally
iOutputStream.Free;
end;
finally
iBitmap.Free;
end;
finally
iImageEnProc.Free;
end;
finally
iBMPStream.Free;
end;
finally
iImageEnIO.Free;
end;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
end.
When this is executed, when you open a bitmap from a file it appears in
Image 1. When you convert the image to PNG it appears in Image2 with full transparency.
This works correctly here with TImage, so if the component you are using correctly supports the alphachannel then it should work as well with similar code.
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development