Solved

make a tranparent bmp ??

Posted on 1999-01-06
4
368 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …

821 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