Delphi - I need to pass a TPrinter canvas to a TBitmap canvas
Delphi - I need to pass a TPrinter canvas to a TBitmap canvas
So I've filled a canvas on my printer object and it prints perfectly. Now I need to save to a file that same canvas that's filled in the printer.canvas. I know I can save a bitmap object and I thought I could just instantiate a bitmap and assign it the printer canvas, but alas, its read-only. This is the line with the error. Anyone has any idea?
bitmapAGuardar.Canvas := Printer.Canvas;
What you are asking for cannot be done like this. It would probably be easier to just draw everything to the bitmap first, and then you can print the bitmap, and save it
– Remy Lebeau
Aug 22 at 18:58
1 Answer
1
This isn't how to do it, and in fact what you ask can't be done.
Write a function that receives a canvas as its parameter. Have that function perform the necessary drawing. When you need to print to a printer call the function passing the printer canvas. When you need to save to a bitmap, call the function passing the bitmap canvas.
You'll likely need to account for the fact that the printer canvas resolution will be much greater than the resolution you want for the bitmap.
even if they are the same type of object?
– Dante
Aug 22 at 18:10
I stand by my answer
– David Heffernan
Aug 22 at 18:17
@Dante - Yes, you can't switch objects as you wish. And if you could, your code would leak the bitmap canvas. When they support it you use "Assign" to assign properties. Additionally, actually a printer canvas is of a "TPrinterCanvas" type, they are not the same type of object. Additionally you'll find yourself doing a lot of scaling, displaying what you'd print is not as easy as it sounds.
– Sertac Akyuz
Aug 22 at 18:26
@SertacAkyuz "Additionally, actually a printer canvas is of a "TPrinterCanvas" type, [and a bitmap canvas is of a "TBitmapCanvas" type, so] they are not the same type of object."
– Remy Lebeau
Aug 22 at 18:56
bummer, thanks :(
– Dante
Aug 22 at 19:54
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
was a question-typo, code did not have it, am editting my question :P
– Dante
Aug 22 at 17:49