1
Graphics / Drawing grid lines on a transparent image
« Last post by Tomi on Today at 04:15:29 pm »Hello!
I would like draw some lines for a grid in my program onto a TImage, but my code always shows a black background under the grid.
As I did so far on the based on my modest knowledge and searching on the internet, I draw a TImage on a ScrollBox and make an other TImage on this and a bitmap onto this with the grid lines.
Here is my code:
How can I make a transparent image with draw on it to show only its draw onto an other image? Is it possible?
I would like draw some lines for a grid in my program onto a TImage, but my code always shows a black background under the grid.
As I did so far on the based on my modest knowledge and searching on the internet, I draw a TImage on a ScrollBox and make an other TImage on this and a bitmap onto this with the grid lines.
Here is my code:
- procedure TForm1.gridButtonMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var bm: TBitmap;
- hlines,vlines: word;
- begin
- if showgrid=true then
- begin
- showgrid:=false;
- if gridon=true then
- begin
- FreeAndNil(gridimage);
- gridon:=false;
- end;
- end
- else
- begin
- showgrid:=true;
- if gridon=false then
- begin
- gridimage:=TImage.Create(terrainScrBox);
- gridimage.Parent:=terrainScrBox;
- gridimage.Left:=0;
- gridimage.Top:=0;
- gridimage.width:=terrainCanvas.width; //terrainCanvas is a TImage component.
- gridimage.height:=terrainCanvas.Height;
- gridimage.Transparent:=true;
- bm:=TBitmap.Create;
- bm.width:=terrainCanvas.width;
- bm.height:=terrainCanvas.Height;
- bm.PixelFormat:=pf32Bit;
- bm.Transparent:=true;
- vlines:=tilewidth;
- hlines:=tileheight;
- bm.canvas.pen.color:=clBlue;
- while vlines<terrainCanvas.width do
- begin
- bm.canvas.line(vlines,0,vlines,terrainCanvas.height);
- inc(vlines,tilewidth);
- end;
- while hlines<terrainCanvas.height do
- begin
- bm.canvas.line(0,hlines,terrainCanvas.width,hlines);
- inc(hlines,tileheight);
- end;
- gridimage.picture.graphic:=bm;
- FreeAndNil(bm);
- end;
- gridon:=true;
- end;
- end;
How can I make a transparent image with draw on it to show only its draw onto an other image? Is it possible?