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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. VC# - Drawing an Image to a Control

VC# - Drawing an Image to a Control

Scheduled Pinned Locked Moved C#
graphicsquestioncsharpdata-structures
4 Posts 2 Posters 1 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.
  • S Offline
    S Offline
    Shailesh Appukuttan
    wrote on last edited by
    #1

    I have a picturebox (imgViewer) which is displaying an image. Now i want to display another image (a smaller one) on top of this image. This is what i was doing: private void btn_Path_Click(object sender, EventArgs e) { Bitmap path = new Bitmap(@"C:\Engg\Path.JPG"); Graphics graph = this.imgViewer.CreateGraphics(); graph.DrawImage(path, 0, 0); graph.Dispose(); } But nothing happens when i push my button (btn_Path). But when i change the code to draw on my form (instead of my picturebox), it works: Graphics graph = this.CreateGraphics(); it properly paints on the form. What is wrong????? How can I paint on my picturebox which is already displaying an image?

    C 1 Reply Last reply
    0
    • S Shailesh Appukuttan

      I have a picturebox (imgViewer) which is displaying an image. Now i want to display another image (a smaller one) on top of this image. This is what i was doing: private void btn_Path_Click(object sender, EventArgs e) { Bitmap path = new Bitmap(@"C:\Engg\Path.JPG"); Graphics graph = this.imgViewer.CreateGraphics(); graph.DrawImage(path, 0, 0); graph.Dispose(); } But nothing happens when i push my button (btn_Path). But when i change the code to draw on my form (instead of my picturebox), it works: Graphics graph = this.CreateGraphics(); it properly paints on the form. What is wrong????? How can I paint on my picturebox which is already displaying an image?

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      change to: private void btn_Path_Click(object sender, EventArgs e) { Bitmap path = new Bitmap(@"C:\Engg\Path.JPG"); Graphics graph = Graphics.FromImage( this.imgViewer.Image ); graph.DrawImage(path, 0, 0); graph.Dispose(); } This should draw the "Path.JPG" on top of the stored image in the PictureViewer.

      S 1 Reply Last reply
      0
      • C CKnig

        change to: private void btn_Path_Click(object sender, EventArgs e) { Bitmap path = new Bitmap(@"C:\Engg\Path.JPG"); Graphics graph = Graphics.FromImage( this.imgViewer.Image ); graph.DrawImage(path, 0, 0); graph.Dispose(); } This should draw the "Path.JPG" on top of the stored image in the PictureViewer.

        S Offline
        S Offline
        Shailesh Appukuttan
        wrote on last edited by
        #3

        hey awsome dude.......... ur brilliant. it worked!!!!! could u do me a favour and tell me what the difference was. I mean why was it working for the form and not for the picture box. they are both controls isnt it. Thanks once again!!!!!

        C 1 Reply Last reply
        0
        • S Shailesh Appukuttan

          hey awsome dude.......... ur brilliant. it worked!!!!! could u do me a favour and tell me what the difference was. I mean why was it working for the form and not for the picture box. they are both controls isnt it. Thanks once again!!!!!

          C Offline
          C Offline
          CKnig
          wrote on last edited by
          #4

          I guess the PictureBox get's an Invalidated message after you painted in it's client-area - so it just did what it should do after it's client-area got invalid - it painted it's internal image in it - and so undid your changes. Even if your code worked - everytime the picturebox would repaint itself your changes would be gone.

          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