Halaman

Sabtu, 24 September 2011

Delphi : Load png to TBitmap

HI there good friends, for those of you who would like to get load a jpeg image and then load the data to a TBitmap object, here is a neat good trick to get it done :

procedure TForm1.btn1Click(Sender: TObject);
var
	bmp : TBitmap;
begin
    if(dlgOpenPic1.Execute()) then
    begin
        img1.Picture.LoadFromFile(dlgOpenPic1.FileName);

        bmp := TBitmap.Create;
        try
            bmp.Width := img1.Picture.Width;
            bmp.Height := img1.Picture.Height;

            bmp.Canvas.Draw(0, 0, img1.Picture.Graphic);

            Canvas.Draw(btn1.Left, btn1.Top + btn1.Height + 20, bmp);
        finally
            bmp.Free;
        end;
    end;
end;
Just dont forget to include the jpeg unit if you want to work with the jpegs, and for delphi 2009 and up you could add the PNGImage to work with png files on your delphi project

Have fun dear friends! ;)

Tidak ada komentar:

Posting Komentar