delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Easiest Way Drawing Transparent ImageFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Graphic
Skill Level:
Scoring:
Last Update:
03/20/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Draw Transparent Image
Times Scored:
4
Visits:
3366
Uploader: h4ry p
Company:
Reference: www.geocities.com/h4ryp/delphi.html
 
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 you image.






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
real names !
    PEPS ^^ (Apr 2 2002 8:16PM)

hi h4ry ??

please enter your real name...

thanks
bernhard

DELPHI3000 - Admin
Respond

RE: real names !
h4ry (Apr 3 2002 11:46AM)

my name is simple: hary.

Respond

Anujit Srinamon
Anujit Srinamon (Nov 8 2005 5:43AM)

I want to get this Code For my Project. Thank.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)