Recent

Author Topic: How to create transparent bitmap?  (Read 8750 times)

haword

  • New Member
  • *
  • Posts: 13
How to create transparent bitmap?
« on: May 22, 2007, 11:47:58 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
RE: How to create transparent bitmap?
« Reply #1 on: May 22, 2007, 11:52:29 am »
at this moment is is not possible to draw transparent yet. This will be added in the near future
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1890
RE: How to create transparent bitmap?
« Reply #2 on: May 22, 2007, 12:44:28 pm »
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

  • New Member
  • *
  • Posts: 13
Re: RE: How to create transparent bitmap?
« Reply #3 on: May 22, 2007, 01:08:10 pm »
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;

Hi Theo! Thanks. I and did earlier. But wished to make a transparency without usage TCanvasOPBitmap. Use only internal resources Lzarus.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
RE: Re: RE: How to create transparent bitmap?
« Reply #4 on: May 22, 2007, 06:18:57 pm »
What is a OPBitmap ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1890
Re: RE: Re: RE: How to create transparent bitmap?
« Reply #5 on: May 22, 2007, 09:11:33 pm »
Quote from: "Marc"
What is a OPBitmap ?


OPBitmap itself is sort of a VCL compatibility layer.
You can reuse code working with scanline accesss, pixelformat conversions etc the way you're used to from the VCL.

http://www.theo.ch/lazarus/opbitmap1_5.zip