Solved

make a tranparent bmp ??

Posted on 1999-01-06
4
359 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
ID: 1354847

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
ID: 1354848
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
ID: 1354849
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
ID: 1354850
see comment
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

770 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