procedure TileDraw(Canvas: TCanvas; const Rect: TRect; G: TGraphic);
var
R, Rows, C, Cols: Integer;
ClipRgn: THandle;
begin
if not G.Empty then
begin
Rows := ((Rect.Bottom - Rect.Top) div G.Height) + 1;
Cols := ((Rect.Right - Rect.Left) div G.Width) + 1;
ClipRgn := CreateRectRgnIndirect(Rect);
try
SelectClipRgn(Canvas.Handle, ClipRgn);
finally
DeleteObject(ClipRgn);
end;
for R := 1 to Rows do
for C := 1 to Cols do
Canvas.Draw(Rect.Left + (C-1) * G.Width, Rect.Top + (R-1) * G.Height, G);
SelectClipRgn(Canvas.Handle, 0);
end;
end;
TileDraw(Bitmap.Canvas, Bitmap.Canvas.ClipRect, AnotherBitmap);
procedure TForm1.FormPaint(Sender: TObject);
begin
// Image1.Visible is False
TileDraw(Canvas, ClientRect, Image1.Picture.Graphic);
end;
function ThumbnailDraw(Canvas: TCanvas; const Rect: TRect;
ThumbWidth, ThumbHeight, Margin: Integer;
Graphics: array of TGraphic): Integer;
function ShrinkRect(const R: TRect; G: TGraphic): TRect;
var
iW, iH: Integer;
rW, rH: Integer;
begin
iW := G.Width;
iH := G.Height;
rW := R.Right - R.Left;
rH := R.Bottom - R.Top;
if (iW > rW) or (iH > rH) then // Shrink only
begin
if (rW / iW) < (rH / iH) then
begin
iH := MulDiv(iH, rW, iW);
iW := rW;
end
else
begin
iW := MulDiv(iW, rH, iH);
iH := rH;
end;
end;
SetRect(Result, 0, 0, iW, iH);
OffsetRect(Result, R.Left + (rW - iW) div 2, R.Top + (rH - iH) div 2);
end;
var
ThumbRect: TRect;
ClipRgn: THandle;
I: Integer;
begin
Result := 0;
ClipRgn := CreateRectRgnIndirect(Rect);
try
SelectClipRgn(Canvas.Handle, ClipRgn);
finally
SelectClipRgn(Canvas.Handle, 0);
end;
SetRect(ThumbRect, 0, 0, ThumbWidth, ThumbHeight);
OffsetRect(ThumbRect, Rect.Left, Rect.Top);
for I := Low(Graphics) to High(Graphics) do
begin
Canvas.StretchDraw(ShrinkRect(ThumbRect, Graphics[I]), Graphics[I]);
OffsetRect(ThumbRect, ThumbWidth + Margin, 0);
Inc(Result);
if ThumbRect.Left >= Rect.Right then
begin
OffsetRect(ThumbRect, Rect.Left - ThumbRect.Left, ThumbWidth + Margin);
if ThumbRect.Top > Rect.Bottom then Break;
end;
end;
SelectClipRgn(Canvas.Handle, 0);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
ThumbnailDraw(Canvas, ClientRect, 150, 150, 0,
[Image1.Picture.Graphic, Image2.Picture.Graphic,
Image3.Picture.Graphic, Image4.Picture.Graphic]);
end;
while ( Y < BMP.Height + dY ) and ( I <> ImageENMView1.ImageCount ) do begin
X := 0;
while ( X < BMP.Width - X ) and ( I <> ImageENMView1.ImageCount ) do begin
TempBMP := ImageEnMView1.GetBitmap ( I );
dX := TempBMP.Width + HBorder;
dY := TempBMP.Height + VBorder;
BMP.Canvas.Draw ( X, Y, TempBMP );
BMP.Canvas.TextOut ( X, Y + TempBMP.Height, ImageEnMView1.ImageBottomText[I].Caption );
Inc ( X, dX );
ImageEnMView1.ReleaseBitmap ( I );
if I <> ImageENMView1.ImageCount then
Inc ( I );
end;
Inc ( Y, dY + 20 );
end;
procedure CreateContactSheet;
var
BMP: TBitmap;
TempBMP: TBitmap;
I: integer;
begin
BMP := TBitmap.Create;
TempBMP := TBitmap.Create;
BMP.Width := //?? Printer.PageWidth - (LeftMargin + RightMargin);
BMP.Height := //?? Printer.PageHeight - (TopMargin + BottomMargin);
for I = 0 to ThumbView1.ImageCount-1 do
TempBMP := ThumbView1.GetBitmap ( I );
ThumbnailDraw(BMP.Canvas, ClientRect, 150, 150, 0, [TempBMP]);
procedure TMainForm.CreateContactSheet2;
var
IE: TImageEnView;
BMP: TBitmap;
TempBMP: TBitmap;
I: integer;
GraphicsArray: array of TGraphic;
begin
IE := TImageEnView.Create ( nil );
try
BMP := TBitmap.Create;
try
BMP.Width := ( ( PageSetupDialog1.PageWidth ) -(PageSetupDialog1.MarginLeft + PageSetupDialog1.MarginRight ) ) div 2;
BMP.Height := ( ( PageSetupDialog1.PageHeight ) - ( PageSetupDialog1.MarginTop + PageSetupDialog1.MarginBottom ) ) div 10;
BMP.PixelFormat := pf24bit;
TempBMP := TBitmap.Create;
I := 0;
SetLength(GraphicsArray, ImageEnMView1.ImageCount);
for i := 0 to ImageEnMView1.ImageCount - 1 do begin
TempBMP := ImageEnMView1.GetBitmap ( I );
GraphicsArray[I] := TempBMP;
end;
ThumbnailDraw ( BMP.Canvas, ClientRect, 150, 150, 0, GraphicsArray );
ImageEnMView1.ReleaseBitmap ( I );
fProperties.ContactSheet1.Blank;
fProperties.ContactSheet1.IEBitmap.Assign ( BMP );
end;
ThumbnailDraw ( BMP.Canvas, ClientRect, 150, 150, 0, GraphicsArray );
ThumbnailDraw ( BMP.Canvas, BMP.Canvas.ClipRect, 150, 150, 0, GraphicsArray );
ThumbnailDraw ( BMP.Canvas, BMP.Canvas.ClipRect, 150, 150, 0, GraphicsArray );
BMP.Width := ( ( PageSetupDialog1.PageWidth ) - ( PageSetupDialog1.MarginLeft + PageSetupDialog1.MarginRight ) ) div 2;
BMP.Height := ( ( PageSetupDialog1.PageHeight ) - ( PageSetupDialog1.MarginTop + PageSetupDialog1.MarginBottom ) ) div 10;
BMP.PixelFormat := pf24bit;
TempBMP := TBitmap.Create;
X := 0;
Y := 0;
I := 0;
SetLength ( GraphicsArray, ImageEnMView1.ImageCount );
SetLength ( CaptionArray, ImageEnMView1.ImageCount );
for i := 0 to ImageEnMView1.ImageCount - 1 do begin
TempBMP := ImageEnMView1.GetBitmap ( I );
GraphicsArray[I] := TempBMP;
CaptionArray[I] := ImageEnMView1.ImageBottomText[I].Caption;
end;
fContactSheet.fBorder := fProperties.UpDown9.Position;
fContactSheet.fImageWidth := fProperties.UpDown10.Position;
fContactSheet.fImageHeight := fProperties.UpDown11.Position;
ThumbnailDraw ( BMP.Canvas, BMP.Canvas.ClipRect{ClientRect}, fContactSheet.fImageWidth, fContactSheet.fImageHeight, fContactSheet.fBorder, GraphicsArray, CaptionArray );
Kambiz wrote:So, you had already the solution.
Users browsing this forum: No registered users and 1 guest