Joan Venge
Joan Venge

Reputation: 331260

How to copy a System.Drawing.Image value?

I am trying to copy an Image value to draw on it and on second draw ignore the last one and start over on top of the preserved Image value. I.e.:

Image with 4 rectangle (ImageA)
-> draw a circle
return to ImageA
-> draw a rectangle
now there are 5 rectangles

I don't know if it's the optimal way to draw too?

Upvotes: 3

Views: 12815

Answers (2)

Sepai
Sepai

Reputation:

I agree with Blindy. Create a new Image object and draw ontop of that while preserving your initial Image.

Bitmap myBitmap = new Bitmap("C:\\<path");
Image myImage = (Image)myBitmap.Clone();

This will create a new Image object for you to then do your drawing on whilst still preserving the original image that you've loaded.

Upvotes: 7

Blindy
Blindy

Reputation: 67427

You can create a new Bitmap and put a Graphics object over it, then draw ImageA over the temporary bitmap and draw your circle on it, and when you're done dispose the temporary bitmap and keep drawing on ImageA.

Upvotes: 0

Related Questions