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. Capturing a perticular part of an Image

Capturing a perticular part of an Image

Scheduled Pinned Locked Moved C#
tutorial
3 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.
  • N Offline
    N Offline
    Nagendra Kamath K
    wrote on last edited by
    #1

    I have an Image. I wanted a perticular part of that image of know dimensions that is the Rectangle is know. Can some one tell me how to get this perticular part of the Image. Cheers

    W 1 Reply Last reply
    0
    • N Nagendra Kamath K

      I have an Image. I wanted a perticular part of that image of know dimensions that is the Rectangle is know. Can some one tell me how to get this perticular part of the Image. Cheers

      W Offline
      W Offline
      wibblewibblewibble
      wrote on last edited by
      #2

      I am new to C# and .net so there may be a more elegant solution , but the you could do it is as follows; // assume IA is a rectangle that defines the area // of the image you want to crop to and the original // image is in origImage......... Bitmap bmp_cropped = new Bitmap(IA.width, IA.height); Graphics g = Graphics.FromImage(bmp_cropped); g.DrawImage(origImage, 0, 0, IA, GraphicsUnit.Pixel); Hope this is of use. Barry

      S 1 Reply Last reply
      0
      • W wibblewibblewibble

        I am new to C# and .net so there may be a more elegant solution , but the you could do it is as follows; // assume IA is a rectangle that defines the area // of the image you want to crop to and the original // image is in origImage......... Bitmap bmp_cropped = new Bitmap(IA.width, IA.height); Graphics g = Graphics.FromImage(bmp_cropped); g.DrawImage(origImage, 0, 0, IA, GraphicsUnit.Pixel); Hope this is of use. Barry

        S Offline
        S Offline
        Stephane David
        wrote on last edited by
        #3

        You can also use Bitmap.Clone. It lay you specify a rectangle, which is the part of the image. With Clone, the resulting image will keep the PixelFormat of the source. For instance, if your first image is 8 bits per pixel, indexed, the cloned image will be also. If you use the other method, with DrawImage, the image must be at least 16bpp I think.

        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