Solved

make a tranparent bmp ??

Posted on 1999-01-06
4
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

710 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