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. C#
  4. Bitmap - show a rectangle area only

Bitmap - show a rectangle area only

Scheduled Pinned Locked Moved C#
graphicsquestion
6 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.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    I don't know whats the failure of this code: Image src = Image.FromFile(@"C:\_sc\test.bmp"); Graphics gr = Graphics.FromImage(src); gr.DrawImageUnscaled(src, 10, 10, 50, 50); Bitmap bmp = new Bitmap(50, 50, gr); pcCuted.Image = bmp; pcCuted.Invalidate(); I load the test.bmp and redraw it new. So I make a new rectangle (50w,50h) and want to put only this area into the pcCuted Picturebox. Doesn't work. Any way to do it right?

    J 1 Reply Last reply
    0
    • S Seraphin

      I don't know whats the failure of this code: Image src = Image.FromFile(@"C:\_sc\test.bmp"); Graphics gr = Graphics.FromImage(src); gr.DrawImageUnscaled(src, 10, 10, 50, 50); Bitmap bmp = new Bitmap(50, 50, gr); pcCuted.Image = bmp; pcCuted.Invalidate(); I load the test.bmp and redraw it new. So I make a new rectangle (50w,50h) and want to put only this area into the pcCuted Picturebox. Doesn't work. Any way to do it right?

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      You were redrawing back onto the same image as you were reading from Image src = Image.FromFile(@"C:\_sc\test.bmp"); Bitmap bmp = new Bitmap(50,50); Graphics gr = Graphics.FromImage(bmp); gr.DrawImageUnscaled(src, 10, 10, 50, 50); pcCuted.Image = bmp; pcCuted.Invalidate();

      S 1 Reply Last reply
      0
      • J J4amieC

        You were redrawing back onto the same image as you were reading from Image src = Image.FromFile(@"C:\_sc\test.bmp"); Bitmap bmp = new Bitmap(50,50); Graphics gr = Graphics.FromImage(bmp); gr.DrawImageUnscaled(src, 10, 10, 50, 50); pcCuted.Image = bmp; pcCuted.Invalidate();

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        ok, but this still doesn't work Image src = Image.FromFile(@"C:\_sc\test.bmp"); Graphics gr = Graphics.FromImage(src); gr.DrawImageUnscaled(src, 10, 10, 50, 50); Bitmap bmp = new Bitmap(50, 50, gr); pcCuted.Image = bmp; pcCuted.Invalidate();

        J 1 Reply Last reply
        0
        • S Seraphin

          ok, but this still doesn't work Image src = Image.FromFile(@"C:\_sc\test.bmp"); Graphics gr = Graphics.FromImage(src); gr.DrawImageUnscaled(src, 10, 10, 50, 50); Bitmap bmp = new Bitmap(50, 50, gr); pcCuted.Image = bmp; pcCuted.Invalidate();

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          In english we use "Thankyou for your help, however i am still having difficulties" I took the time to actually type that code into a new windows project and tested it with an image locally, it did exactly what you asked for - draw a section (10,10,50,50) of the original image into the picture box. And the best you can give is "still doesnt work" X| I'll tell you what, if you tell me WHAT doesnt work, ill even have another try - that is as long as you're a little more polite this time :|

          S 1 Reply Last reply
          0
          • J J4amieC

            In english we use "Thankyou for your help, however i am still having difficulties" I took the time to actually type that code into a new windows project and tested it with an image locally, it did exactly what you asked for - draw a section (10,10,50,50) of the original image into the picture box. And the best you can give is "still doesnt work" X| I'll tell you what, if you tell me WHAT doesnt work, ill even have another try - that is as long as you're a little more polite this time :|

            S Offline
            S Offline
            Seraphin
            wrote on last edited by
            #5

            Hi, Either I thank you in advance, problem is solved or finally no solutin was found. I have now a solution, thank for your response and the tip (finally it was the right way). PS: Every tip is automatically accepted thanks. It's naturally. So why should people post their thanks in an extra thread and wasting space?

            M 1 Reply Last reply
            0
            • S Seraphin

              Hi, Either I thank you in advance, problem is solved or finally no solutin was found. I have now a solution, thank for your response and the tip (finally it was the right way). PS: Every tip is automatically accepted thanks. It's naturally. So why should people post their thanks in an extra thread and wasting space?

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

              Seraphin wrote:

              PS: Every tip is automatically accepted thanks. It's naturally. So why should people post their thanks in an extra thread and wasting space?

              Because it gives the person who tried to help you a good feeling, and maybe he thinks (i know i do): 'hey that guy is nice, if he asks a question next time i will try to help him again!' And also it's just good manners... 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
              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