Your paint box OnPaint
event handler is probably dedicated to painting to the size of the paint box. You need to generalize the painting code to be able to draw to a general canvas whose size is only known at runtime. That way you can draw to the low resolution paint box and the high resolution file with the same painting code.
Extract the code inside your OnPaint
event handler into a separate method that looks like this:
procedure TForm1.DoPaintBoxPaint(Canvas: TCanvas);
begin
// All painting code goes here. Use Canvas.ClipRect to infer size of canvas.
end;
Then call this method from your OnPaint
handler. Pass PaintBox1.Canvas
as the parameter to the method.
In outline that looks like this:
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
DoPaintBoxPaint(PaintBox1.Canvas);
end;
Finally you can call the method from the method that saves the image to file. In that case I assume you have a temporary bitmap on which to draw the image before saving. Pass the canvas of that bitmap. A sketch of that code would be:
Bitmap := TBitmap.Create;
try
Bitmap.SetSize(Width, Height);
DoPaintBoxPaint(Bitmap.Canvas);
Bitmap.SaveToFile(...);
finally
Bitmap.Free;
end;