views:

151

answers:

2

I am creating a Graphics object to draw on the original image and I want save the modified image as a new image.The Image on the form as well as the drawing

+1  A: 
 //load bitmap from file
 Image bmp = Image.FromFile();

Graphics g = Graphics.FromImage(bmp);

//do drawing here with g.

bmp.Save();

g.Dispose()
Benny
Your need execute g.Dispose() after drawing
DreamWalker
@Dreamwalker, thanks.
Benny
@Benny, I think that you need execute g.Dispose() after drawing, but before bmp.Save() for correct work
DreamWalker
+1  A: 
    Bitmap newBitmap = new Bitmap(originalBitmap);
    using (Graphics myGraphics = Graphics.FromImage(newBitmap))
    {
        // draw here on myGraphics
    }
    // newBitmap - modified image

Alternatively with Load & Save:

    Bitmap myBitmap = new Bitmap("fileName.bmp");
    using (Graphics myGraphics = Graphics.FromImage(myBitmap))
    {
        // draw here on myGraphics
    }
    myBitmap.Save("newFileName.bmp");
DreamWalker
no need to build a new image, just save with a different file name.
Benny
@Benny, I don't know best variant for author, but I added alternatively version.
DreamWalker