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
2009-10-08 05:28:35
Your need execute g.Dispose() after drawing
DreamWalker
2009-10-08 05:31:27
@Dreamwalker, thanks.
Benny
2009-10-08 05:33:16
@Benny, I think that you need execute g.Dispose() after drawing, but before bmp.Save() for correct work
DreamWalker
2009-10-08 05:35:25
+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
2009-10-08 05:30:22
@Benny, I don't know best variant for author, but I added alternatively version.
DreamWalker
2009-10-08 05:47:54