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;





was a question-typo, code did not have it, am editting my question :P
– Dante
Aug 22 at 17:49





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)