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. define crop from picturebox?

define crop from picturebox?

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 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.
  • C Offline
    C Offline
    crash893
    wrote on last edited by
    #1

    Hey all, I need to load a photo, Display it in a picturebox then "draw" a rectangle area that i want to crop an example would be if i wanted to make a head shot out of a regular photo i know how to find and load the photo in to the picture box but I'm not sure how to define the crop i want any ideas

    A 1 Reply Last reply
    0
    • C crash893

      Hey all, I need to load a photo, Display it in a picturebox then "draw" a rectangle area that i want to crop an example would be if i wanted to make a head shot out of a regular photo i know how to find and load the photo in to the picture box but I'm not sure how to define the crop i want any ideas

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      add in some mouse events for the picture box. When the user clicks with the mouse, register its location (so, a start point) When the user releases, register the loaction and you have an end point. Now, create a new bitmap the same width and hieght as your selected area. Create a new graphics object from your new bitmap (Graphics.FromImage) Then draw the selected area of the picture box's image, to your new bitmap Rectangle srcRect = new Rectangle(start.x, start.y, end.x-start.x, end.y-start.y) myGraphics.DrawImage(myPictureBox.Image, 0,0, srcRect, GraphicsUnit.Pixel) Then, set your pictures image to the bitmap you created earlier. Don't forget to dispose of your graphics objects and whatnot. You also may need to add some checking between the start and end points, so you don't have any negative values around. As for drawing the rectangle you want to crop as your dragging the mouse, register for the OnPaint event, and draw a rectangle between the start point, and the current location of the mouse. I hope i havn't been to confusing there, i just kinda typed as i thought.

      My current favourite word is: Waffle Cheese is still good though.

      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