Doh! "A dog returns to his vomit as a fool to his folly". I keep making that same mistake when trying to create objects.
Right, I have the TBitmap creating correctly and my generateLayoutOnCanvas function seems to accept it as a parameter, but I am now back to wheer I was last week with CopyRect() in that all I am getting is a solid black box in the image.
I just can't seem to get CopyRect to work.
This is what I have at the moment, with some feedback on the sizing and scaling calculations:
procedure TMainForm.updatePreview();
var
scaleFactorX, scaleFactorY: Double;
previewXsize, previewYsize: Int64;
myBitMap: TBitmap;
begin
scaleFactorX:=Printer.XDPI / Screen.PixelsPerInch;
scaleFactorY:=Printer.YDPI / Screen.PixelsPerInch;
previewXsize:=Round(Printer.PageWidth/scaleFactorX);
previewYsize:=Round(Printer.PageHeight/scaleFactorY);
showMessage('Printer PageWidth = '+FloatToStr(Printer.PageWidth)+', Printer PageHeight = '+FloatToStr(Printer.PageHeight)+sLineBreak+
'X-Scale = '+FloatToStr(scaleFactorX)+', Y-Scale = '+FloatToStr(scaleFactorY)+sLineBreak+
'Preview X-Size = '+FloatToStr(previewXsize)+', Preview Y-Size = '+FloatToStr(previewYsize));
iLabelPreview.Width:=previewXsize;
iLabelPreview.Height:=previewYsize;
try
begin
myBitMap:=TBitmap.Create;
generateLabelLayoutOnCanvas(myBitMap.Canvas, previewXsize, previewYsize);
iLabelPreview.Canvas.CopyRect(Rect(0,0,iLabelPreview.Width,iLabelPreview.Height),
myBitMap.Canvas,
Rect(0,0,previewXsize,previewYsize));
// iLabelPreview.Picture.Bitmap:=myBitMap;
end;
finally
myBitMap.Free;
end;
end;
(iLabelPreview is a TImage and it is in a TScrollBox as you suggested - I actually meant TImage when I asked which was best between TBitMap and TPaintBox, and already had them in a scrollbox so at least I was doing something right even if it was only in the interface design approach rather than the coding ;-P)
-FM