4

I currently have a Image in my project, onto which I have placed a rectangle (which moves when you press arrow keys). What I aim to do is to let the user move this rectangle to show which area of the image is to be the result after cropping. See below for screenshot. The rectangle is W:60;H:150;

Crop

What I want to happen next is for a button to be clicked, and the area which the rectangle covers to be transferred into another image container sized the same as the rectangle.

So far I could not achieve this after scouring google... Would any of you be kind enough to assist?

Thanks!

Meh
  • 607
  • 1
  • 9
  • 19
  • 5
    Check this link: http://www.codeproject.com/Articles/20245/WPF-Interactive-Image-Cropping-Control – Prashant Apr 25 '12 at 13:44
  • surely there should be a more efficient way of doing this... :( – Meh Apr 25 '12 at 14:03
  • 1
    Have you taken a look at Paint.NET? I believe it's open source so you could check their implementation. – Ian Apr 25 '12 at 14:04

1 Answers1

1

You need to use CroppedBitmap class

 <CroppedBitmap x:Key="croppedImage" 
      Source="{StaticResource masterImage}" SourceRect="30 20 105 50"/>

replace the sourcerect with the rect coordinates of your rectangle

Dean Chalk
  • 20,076
  • 6
  • 59
  • 90
  • could you elaborate on this a little further. This looks promising. Would this need to be declared in any special way inside the xaml? If so, what approach should I take? – Meh Apr 25 '12 at 15:29
  • 1
    heres an example of it being used http://www.codeproject.com/Articles/23158/A-Photoshop-like-Cropping-Adorner-for-WPF – Dean Chalk Apr 25 '12 at 15:31
  • OK I have implemented this. With one small hitch... The way I have my "move" setup for the rectangle does move the crop area as well. But, only after the initial application load. If i do anything like click on a check box, then the move does not work anymore... Is this a focus related issue or am i capturing keys incorrectly – Meh Apr 25 '12 at 20:30
  • @Meh could be that "Property changes can occur only during object initialization. Call BeginInit to signal that initialization has begun and EndInit to signal that initialization has completed. After initialization, property changes are ignored." https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.croppedbitmap.aspx#Syntax – StayOnTarget Jul 13 '18 at 12:10