简体   繁体   中英

How to copy a System.Drawing.Graphics over another Graphics?

We got some code that implement printing using Printdocument and it does all the drawing directly on the Graphics object received in the PrintEventArgs . It would be more convenient if the code doing the drawing used another canvas and we would add this canvas to the PrintEventArgs Graphics after. Since the code already depends on the Graphics object I need a canvas with this object. I also need a way to copy the canvas onto the PrintEventArgs Graphics . I can create a Graphics from an Image but as far as I know it needs to be stored on the disk. Any suggestions?

Create an empty bitmap, get the bitmap's graphics object, and do your painting on that. You can save the bitmap to disk or wherever if you need to retrieve it later. Then paint the bitmap on top of your graphics object whenever you need that layer to be added. Should be pretty straightforward.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM