problem with transparency lazarus / 39-Graphics ---------------------------------------------------------------------- Blue1987 · 2011-04-14 00:13 can anyone explain me what's wrong with this code?? Code: [Select]  image1.Canvas.Brush.Color:=clblue;   image1.canvas.FillRect(0,0,image1.Width,image1.height);   image2.Transparent:=true;   {image2.Picture.Bitmap.TransparentColor:=clblack;   image2.Canvas.Brush.Color:=clblack;   image2.canvas.FillRect(0,0,image2.Width,image2.height);}   image2.canvas.Pen.Color:=clred;   image2.Canvas.Pen.Style:=pssolid;   image2.Canvas.Line(0,image2.height,image2.width,0); i simply would like image1 to stay in the background, and image2 to show the red line only (and the rest transparent)... thank you, Paolo ---------------------------------------------------------------------- Blue1987 · 2011-04-14 00:17 this is the output when I compile the code (if I also use the code in the {}brackets it simply shows the blue square) ---------------------------------------------------------------------- lainz · 2011-04-14 01:10 Quote from: Blue1987 on April 14, 2011, 02:13:52 amcan anyone explain me what's wrong with this code?? ... i simply would like image1 to stay in the background, and image2 to show the red line only (and the rest transparent)... thank you, Paolo Because you are drawing in Canvas, not assigning a Picture to TImage. So you can't use Transparent property in this way. This assign transparency in a temp bitmap, and then draw the bitmap in the image2: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  bmp: TBitmap;begin  image1.Canvas.Brush.Color:=clblue;  image1.canvas.FillRect(0,0,image1.Width,image1.height);   bmp:= TBitmap.Create;  bmp.Width:= image2.Width;  bmp.Height:= image2.Height;   bmp.Transparent:=True;  bmp.TransparentColor:=clBlack;   with bmp.canvas do begin  Pen.Color:=clred;  Pen.Style:=pssolid;  Line(0,image2.height,image2.width,0);  end;   image2.Picture.Assign(bmp);  bmp.Free;end; ---------------------------------------------------------------------- Blue1987 · 2011-04-14 01:37 Quote from: lainz on April 14, 2011, 03:10:50 amQuote from: Blue1987 on April 14, 2011, 02:13:52 amcan anyone explain me what's wrong with this code?? ... i simply would like image1 to stay in the background, and image2 to show the red line only (and the rest transparent)... thank you, Paolo Because you are drawing in Canvas, not assigning a Picture to TImage. So you can't use Transparent property in this way. This assign transparency in a temp bitmap, and then draw the bitmap in the image2: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  bmp: TBitmap;begin  image1.Canvas.Brush.Color:=clblue;  image1.canvas.FillRect(0,0,image1.Width,image1.height);   bmp:= TBitmap.Create;  bmp.Width:= image2.Width;  bmp.Height:= image2.Height;   bmp.Transparent:=True;  bmp.TransparentColor:=clBlack;   with bmp.canvas do begin  Pen.Color:=clred;  Pen.Style:=pssolid;  Line(0,image2.height,image2.width,0);  end;   image2.Picture.Assign(bmp);  bmp.Free;end; thanks a lot! ---------------------------------------------------------------------- GBarton · 2013-03-26 20:57 I have tried the same code by Lainz but Image2 is black (not transparent). Is there any way to make Image2 transparent? I am using Lazarus 1.0.8. ---------------------------------------------------------------------- GBarton · 2013-04-03 22:50 Image2.Transparent:= true and it works