Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Is it possible to remove existing graphics from an image?

Is it possible to remove existing graphics from an image?

Scheduled Pinned Locked Moved Visual Basic
graphicshelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gulfraz Khan
    wrote on last edited by
    #1

    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!

    M R 2 Replies Last reply
    0
    • G Gulfraz Khan

      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!

      M Offline
      M Offline
      Marc 0
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • G Gulfraz Khan

        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!

        R Offline
        R Offline
        Roy Heil
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • R Roy Heil

          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.

          G Offline
          G Offline
          Gulfraz Khan
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups