tags:

views:

318

answers:

2

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?

A: 

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.

Blindy
You mean Graphics.FromImage?
Joan Venge
A: 

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.

Thanks but I only have an Image store, as in the System.Drawing.Image in memory. Can I just use that to pass to a new Image value?
Joan Venge
Sorry i thought you we're loading an Image in as a Bitmap. Yes of course you can do what you're after. Say you're starting off with Image imageA and want to copy that image into a new object the code remains the same as above but without the casting.Image myImage = imageA.Clone();