To draw the grid transparently you must also draw on the alphachannel. This uses OnBackbuffer to draw the grid. Here is one way to do it:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Draw A Grid'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object ImageEnView1: TImageEnView
Left = 0
Top = 0
Width = 635
Height = 299
Background = clBtnFace
ParentCtl3D = False
OnResize = ImageEnView1Resize
BackgroundStyle = iebsChessboard
OnDrawBackBuffer = ImageEnView1DrawBackBuffer
EnableInteractionHints = True
Align = alClient
TabOrder = 0
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, imageenview, ieview, imageenproc, hyieutils, hyiedefs;
type
TForm1 = class(TForm)
ImageEnView1: TImageEnView;
procedure FormShow(Sender: TObject);
procedure ImageEnView1Resize(Sender: TObject);
procedure ImageEnView1DrawBackBuffer(Sender: TObject);
private
{ Private declarations }
procedure CreateHorizontal(i, GridWidth, CanvasWidth: Integer);
procedure CreateVertical(i, GridWidth, CanvasHeight: Integer);
procedure DrawGrid;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateHorizontal(i, GridWidth, CanvasWidth: Integer);
{ Draw horzontal rectangles. }
begin
ImageEnView1.IEBitmap.Canvas.Rectangle(0, 0, CanvasWidth,
i * GridWidth + GridWidth);
ImageEnView1.IEBitmap.AlphaChannel.Canvas.Rectangle(0, 0, CanvasWidth,
i * GridWidth + GridWidth);
end;
procedure TForm1.CreateVertical(i, GridWidth, CanvasHeight: Integer);
{ Draw vertical rectangles. }
begin
ImageEnView1.IEBitmap.Canvas.Rectangle(0, 0, i * GridWidth,
CanvasHeight + GridWidth);
ImageEnView1.IEBitmap.AlphaChannel.Canvas.Rectangle(0, 0, i * GridWidth,
CanvasHeight + GridWidth);
end;
procedure TForm1.DrawGrid;
{ Draw the grid. }
const
iGridWidth: Integer = 50;
var
iMaxWidth: Integer;
i: Integer;
begin
{ Fill the bitmap with white }
ImageEnView1.IEBitmap.Fill(clWhite);
{ Draw a rect around the image }
ImageEnView1.IEBitmap.Canvas.Pen.Style := psSolid;
ImageEnView1.IEBitmap.Canvas.Pen.Width := 1;
ImageEnView1.IEBitmap.Canvas.Pen.Color := clBlack;
ImageEnView1.IEBitmap.Canvas.Rectangle(1, 1, ImageEnView1.IEBitmap.Width-1,
ImageEnView1.IEBitmap.Height-1);
ImageEnView1.IEBitmap.AlphaChannel.Canvas.Rectangle(1, 1, ImageEnView1.IEBitmap.Width-1,
ImageEnView1.IEBitmap.Height-1);
ImageEnView1.IEBitmap.Canvas.Brush.Style := bsClear;
ImageEnView1.IEBitmap.Canvas.Pen.Style := psSolid;
ImageEnView1.IEBitmap.Canvas.Pen.Width := 1;
ImageEnView1.IEBitmap.Canvas.Pen.Color := clBlack;
ImageEnView1.IEBitmap.Canvas.Brush.Style := bsClear;
{ Draw inside rectangles with dots }
ImageEnView1.IEBitmap.Canvas.Pen.Style := psDot;
ImageEnView1.IEBitmap.Canvas.Pen.Width := 1;
ImageEnView1.IEBitmap.Canvas.Pen.Color := clBlack;
iMaxWidth := ImageEnView1.IEBitmap.Width;
for i := 0 to iMaxWidth do
begin
{ Draw the horzontal rectangles }
CreateHorizontal(i, iGridWidth, ImageEnView1.IEBitmap.Width);
{ Draw the vertical rectangles }
CreateVertical(i, iGridWidth, ImageEnView1.IEBitmap.Height);
end;
ImageEnView1.EnableAlphaChannel := True;
{ Make the white transparent }
ImageEnView1.Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255, 255, 255), 0);
ImageEnView1.Update;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
{ Create Transparent bitmap }
ImageEnView1.AlphaChannel.Fill(0);
{ Force the form to redraw itself }
Form1.Width := Form1.Width + 1;
ImageEnView1.Update;
end;
procedure TForm1.ImageEnView1DrawBackBuffer(Sender: TObject);
{ Draw the grid in the backbuffer canvas. }
begin
DrawGrid;
end;
procedure TForm1.ImageEnView1Resize(Sender: TObject);
{ Resize the bitmap to fit the component and redraw the grid. }
begin
ImageEnView1.Proc.ImageResize(ImageEnView1.Width, ImageEnView1.Height, iehCenter, ievCenter, 0);
DrawGrid;
end;
end.
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html