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. WPF
  4. clipping an image region and saving as new image

clipping an image region and saving as new image

Scheduled Pinned Locked Moved WPF
csharphelpwpfgraphicstutorial
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
    coolpjmartin
    wrote on last edited by
    #1

    Help wanted clipping an image region and saving as new image.... Can someone please help me. What I what to do is display a picture (image) and drawer a clip region using the mouse on a selected area on the image, this could be a retangle, square or a freehand shape. I can display the image and clipped region using WPF as below. But what I cannot work out is how to save the clipped region of the image as a new bitmap image. The same problem if I create a image using pathgeometry, I cannot work out how to save the cropped part of the image. If there is an alternative method instead of using WPF, please advice me. c# or vb I don't mind, I just need a solution. Thanks // Sample 4 // Create the image to clip. Image myImage = new Image(); Uri imageUri = new Uri(@"C:\\Documents and Settings\\All Users\\Documents\My Pictures\\Sample Pictures\\Water lilies.jpg", UriKind.Relative); myImage.Source = new BitmapImage(imageUri); myImage.Width = 200; myImage.Height = 150; myImage.HorizontalAlignment = HorizontalAlignment.Left; // Use an EllipseGeometry to define the clip region. EllipseGeometry myEllipseGeometry2 = new EllipseGeometry(); myEllipseGeometry2.Center = new Point(100, 75); myEllipseGeometry2.RadiusX = 100; myEllipseGeometry2.RadiusY = 75; myImage.Clip = myEllipseGeometry2;

    S 1 Reply Last reply
    0
    • C coolpjmartin

      Help wanted clipping an image region and saving as new image.... Can someone please help me. What I what to do is display a picture (image) and drawer a clip region using the mouse on a selected area on the image, this could be a retangle, square or a freehand shape. I can display the image and clipped region using WPF as below. But what I cannot work out is how to save the clipped region of the image as a new bitmap image. The same problem if I create a image using pathgeometry, I cannot work out how to save the cropped part of the image. If there is an alternative method instead of using WPF, please advice me. c# or vb I don't mind, I just need a solution. Thanks // Sample 4 // Create the image to clip. Image myImage = new Image(); Uri imageUri = new Uri(@"C:\\Documents and Settings\\All Users\\Documents\My Pictures\\Sample Pictures\\Water lilies.jpg", UriKind.Relative); myImage.Source = new BitmapImage(imageUri); myImage.Width = 200; myImage.Height = 150; myImage.HorizontalAlignment = HorizontalAlignment.Left; // Use an EllipseGeometry to define the clip region. EllipseGeometry myEllipseGeometry2 = new EllipseGeometry(); myEllipseGeometry2.Center = new Point(100, 75); myEllipseGeometry2.RadiusX = 100; myEllipseGeometry2.RadiusY = 75; myImage.Clip = myEllipseGeometry2;

      S Offline
      S Offline
      sivaddrahcir
      wrote on last edited by
      #2

      RenderTargetBitmap[^] is the key here. Also check out this blog post by Rick Strahl which I found helpful: Rendering a WPF Container to Bitmap[^]

      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