Is it possible to remove existing graphics from an image?
-
Hi I am trying to draw a rectangle over an existing image by using the following code (pb is the PictureBox and has an image)
Dim oGraphics As Graphics = Graphics.FromImage(pb.Image) With oGraphics .DrawRectangle(New Pen(Color.Red, 2), New Rectangle(5, 5, 300, 300)) End With pb.Refresh()
The problem comes when I want to draw another rectangle (at a different location) and I can't remove/clear the existing rectangle before drawing the new one. Is there any way I can remove the existing drawn rectangle? I don't want to use the pb.CreateGraphics() b/c the drawing is not consistent when this method is used. I am using the FromImage() method b/c later I want to resize (zoom) or rotate the image with drawn rectangle and It won't require any further coding for rotating and resizing the rectangle. I tried reload the Image again, but large images take to much time to load, so I want to avoid the Image reloading. Please help! -
Hi I am trying to draw a rectangle over an existing image by using the following code (pb is the PictureBox and has an image)
Dim oGraphics As Graphics = Graphics.FromImage(pb.Image) With oGraphics .DrawRectangle(New Pen(Color.Red, 2), New Rectangle(5, 5, 300, 300)) End With pb.Refresh()
The problem comes when I want to draw another rectangle (at a different location) and I can't remove/clear the existing rectangle before drawing the new one. Is there any way I can remove the existing drawn rectangle? I don't want to use the pb.CreateGraphics() b/c the drawing is not consistent when this method is used. I am using the FromImage() method b/c later I want to resize (zoom) or rotate the image with drawn rectangle and It won't require any further coding for rotating and resizing the rectangle. I tried reload the Image again, but large images take to much time to load, so I want to avoid the Image reloading. Please help!Maybe you can load the image, and the clone it, and the put the clone in the pb? That way, when you want to remove the stuff you were drawing on the image of the pb, you can dispose that image and put a new clone of the original in the pb. I think on large images cloning takes much time too, but less that reloading it. Pompiedompiedom... ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
-
Hi I am trying to draw a rectangle over an existing image by using the following code (pb is the PictureBox and has an image)
Dim oGraphics As Graphics = Graphics.FromImage(pb.Image) With oGraphics .DrawRectangle(New Pen(Color.Red, 2), New Rectangle(5, 5, 300, 300)) End With pb.Refresh()
The problem comes when I want to draw another rectangle (at a different location) and I can't remove/clear the existing rectangle before drawing the new one. Is there any way I can remove the existing drawn rectangle? I don't want to use the pb.CreateGraphics() b/c the drawing is not consistent when this method is used. I am using the FromImage() method b/c later I want to resize (zoom) or rotate the image with drawn rectangle and It won't require any further coding for rotating and resizing the rectangle. I tried reload the Image again, but large images take to much time to load, so I want to avoid the Image reloading. Please help!I haven't worked with graphics for a while, so I don't know how hard this would be, but could you lay down the image first, and then overlay a transparent picturebox on the first image? Then, instead of drawing the rectange directly on the image, you can draw it over the image, on the second picturebox. Roy.
-
I haven't worked with graphics for a while, so I don't know how hard this would be, but could you lay down the image first, and then overlay a transparent picturebox on the first image? Then, instead of drawing the rectange directly on the image, you can draw it over the image, on the second picturebox. Roy.
Thank You Roy, I am not sure and don't remember it correctly (I read it somewhere) that there is something like a Xor Pen. Is there anything like this that can help me? Another CP user in the C# forum suggested me that I should remember the Pixel values of the image (for rectangular area) before drawing the rectangle. How do I remember those values and how to reload those values?