Forum > Graphics
How to create transparent bitmap?
haword:
example:
var
bmp: TBitmap;
begin
bmp:=TBitmap.Create;
bmp.PixelFormat:= pf24bit;
bmp.Height:=16;
bmp.Width:=16;
bmp.TransparentColor:=clBlack;
bmp.Transparent:=true;
bmp.Canvas.Brush.Color:=clBlack;
bmp.Canvas.FillRect(bmp.Canvas.ClipRect);
SpeedButton1.Glyph.TransparentColor:=clBlack;
SpeedButton1.Glyph.Transparent:=true;
SpeedButton1.Glyph.Assign(bmp);
SpeedButton1.Glyph.SaveToFile('test.bmp');
SpeedButton2.Glyph.LoadFromFile('test.bmp');
bmp.Free;
SpeedButton1 show black box, SpeedButton2 show empty, how to create transparent bitmap and show this to SpeedButton1?
Marc:
at this moment is is not possible to draw transparent yet. This will be added in the near future
theo:
You could do it with OpBitmap like this:
var bmp:TBitmap;
opb:TCanvasOPBitmap;
begin
bmp:=TBitmap.create;
opb:=TCanvasOPBitmap.create;
opb.width:=16;
opb.height:=16;
opb.Canvas.Brush.color:=clRed;
opb.Canvas.FillRect(Rect(0,0,16,16));
opb.Canvas.Brush.color:=clBlack;
opb.Canvas.FillRect(Rect(1,1,15,15));
opb.TransparentColor:=opb.Pixels[8,8];
AssignOpBitmapToBitmap(opb,bmp);
opb.free;
SpeedButton1.Glyph.Assign(Bmp);
bmp.free;
haword:
--- Quote from: "theo" ---You could do it with OpBitmap like this:
var bmp:TBitmap;
opb:TCanvasOPBitmap;
begin
bmp:=TBitmap.create;
opb:=TCanvasOPBitmap.create;
opb.width:=16;
opb.height:=16;
opb.Canvas.Brush.color:=clRed;
opb.Canvas.FillRect(Rect(0,0,16,16));
opb.Canvas.Brush.color:=clBlack;
opb.Canvas.FillRect(Rect(1,1,15,15));
opb.TransparentColor:=opb.Pixels[8,8];
AssignOpBitmapToBitmap(opb,bmp);
opb.free;
SpeedButton1.Glyph.Assign(Bmp);
bmp.free;
--- End quote ---
Hi Theo! Thanks. I and did earlier. But wished to make a transparency without usage TCanvasOPBitmap. Use only internal resources Lzarus.
Marc:
What is a OPBitmap ?
Navigation
[0] Message Index
[#] Next page