Question/Problem/Abstract:
How to draw an image transparently ?
Answer:
Here is anohter way to draw a transparent image.
Only using Delphi properties and method (Image).
Here is the example code:
// make draw proc to draw transparently
procedure MyTransparentDraw(src, dest: TBitmap; x, y: integer; warna: TColor);
begin
src.Transparent := true;
src.TransparentMode := tmFixed;
src.TransparentColor := warna;
dest.Canvas.Draw(x, y, src);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
TRANS_COLOR = clYellow; // change with transparent color you want
var bmp, bmp2: TBitmap;
begin
if (OpenPictureDialog1.Execute) then begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
bmp := TBitmap.Create;
try
bmp.Width := Image1.Width;
bmp.Height := Image1.Height;
bmp.Assign(Image1.Picture.Bitmap);
bmp2 := TBitmap.Create;
try
bmp2.Width := bmp.Width;
bmp2.Height := bmp.Height;
MyTransparentDraw(bmp, bmp2, 0, 0, TRANS_COLOR);
Image1.Canvas.Draw(0, 0, bmp2);
finally
bmp2.Free;
end;
finally
bmp.Free;
end;
end;
end;
To try above code, just copy and paste those code,
then click on button to choose an image to be drawn transparently.
You can change the value of "TRANS_COLOR" above with any other color that you want to be the transparent color of your image
ps : original source of this article was uploaded by h4ry p @ delphi3000.com
http://www.delphi3000.com/articles/article_3115.asp
:: My another contributions in Delphi
»Delphi3000.com
»Delphi3000.com
posting and uploading delphi articles
[currently as Top 66 uploader]
»Komunitas Delphi Indonesia
starting as a member
Sunday, November 05, 2006
:: Easiest Way Drawing Transparent Image
Posted by
Heavy Galleon
at
1:51 AM
Labels: programming article
Subscribe to:
Post Comments (Atom)


1 comments:
your code doesn't work =P, or the buttonclick doesn't show the picture i load
Post a Comment