Re: Unable to clone an image
- From: "Steven Garrad" <stevierg@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 13:26:43 +0100
Well I managed to answer it myself...
I save the image as a bitmap:
undoBitmap = new Bitmap(this.Image);
And then draw the bitmap back to the image using a graphic object:
g.DrawImage(System.Drawing.Image.FromHbitmap(undoBitmap.GetHbitmap()), 0, 0, undoBitmap.Width, undoBitmap.Height);
The only strange thing about this is that I have to use the width and height information as for some reason it applies it around 30% smaller without.
"Steven Garrad" <stevierg@xxxxxxxxxxxxxxxxxxx> wrote in message news:6987878C-9291-4366-9B9E-440EA41DADBA@xxxxxxxxxxxxxxxx
Hi There, I need a little help.
I have a class uses the PictureBox as a base.
In this I want to store the current image twice. So I can restore the image when needed.
Right now I create another Image object and when the user hits an apply button it saves the current image into the second image. I use the following:
undoImage = (System.Drawing.Image)this.Image.Clone();
That line appears to work, but my next section causes an OutOfMemoryException Error:
using (Graphics g = Graphics.FromImage(this.Image))
{
g.FillRectangle(myBrush, myRectangle);
this.Invalidate();
g.Dispose();
}
What I don't understand is that if I comment out the line that makes a clone of the image it works fine.
Does anyone know how to do this, or a different way or why this would cause a out of memory exception?
Thanks,
Steve
.
- Follow-Ups:
- Re: Unable to clone an image
- From: Bob Powell [MVP]
- Re: Unable to clone an image
- References:
- Unable to clone an image
- From: Steven Garrad
- Unable to clone an image
- Prev by Date: Unable to clone an image
- Next by Date: Re: Family Tree Diagram
- Previous by thread: Unable to clone an image
- Next by thread: Re: Unable to clone an image
- Index(es):