Solved

make a tranparent bmp ??

Posted on 1999-01-06
4
346 Views
Last Modified: 2013-11-19
how can i make a bmp transparent so i can merge it with another bmp ?
0
Comment
Question by:de_ep
  • 2
4 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility

Dynamically drawing a transparent image
Question:
How do I use a TImageList component to dynamically draw a transparent image?
Answer:
The following example demonstrates the dynamic creation of a
TImageList component used to draw a transparent bitmap.

Example:

procedure TForm1.Button1Click(Sender: TObject);
var
  bm : TBitmap;
  il : TImageList;
begin
  bm := TBitmap.Create;
  bm.LoadFromFile('C:\DownLoad\TEST.BMP');
  il := TImageList.CreateSize(bm.Width,
                              bm.Height);
  il.DrawingStyle := dsTransparent;
  il.Masked := true;
  il.AddMasked(bm, clRed);
  il.Draw(Form1.Canvas, 0, 0, 0);
  bm.Free;
  il.Free;
end;


Tell me if this helped
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
You can simply set "bitmap.transparent:=true".
If you do nothing but this, all colors that have the same color like the color in the pixel "bitmap.canvas.pixels[0,bitmap.height]" are now transparent.
If you want to decide which color is to be transparent, simply write "bitmap.transparentColor:=clWhite".

Regards, Madshi.
0
 
LVL 2

Expert Comment

by:gysbert1
Comment Utility
A little more detail to help you ...

There actually is no such thing as a transparent BMP file (unfortunately). The transparency comes in when you are drawing the image.

Some formats such as GIF does support transparency but once again it is implemented at draw-time similar to what Mirkwood suggested.

This is usually done by marking one of the pallette entries as the transparent entry. Any pixels of this color will then be deemed to be transparent and not printed on the screen.

What Mirkwood is doing up here is exactly that. He is setting clRed as the mask color and setting DrawingStyle := dsTransparent will tell Delphi not to draw any pixels that are red in the image, thus giving a transparent image.

0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 total points
Comment Utility
see comment
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 116
Delphi : could not find program, '...exe' 2 115
AutoCad licenses 9 38
How to debug For loops? 3 33
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now