Reputation: 282885
I've got a large image in memory which I convert to an System.Windows.Media.ImageBrush
and use it as the Fill
for a System.Windows.Shapes.Rectangle
. You can move this rectangle around with your cursor.
Basically I want to use the rectangle as a "viewport". Thus I need to change which parts of the image get displayed within the rectangle, i.e., define a rectangular subsection of the image.
How can I do that?
I see ImageBrush.Viewport but that doesn't seem to mean the same thing.
I'm open to alternative solutions that don't involve a rectangle, such as drawing directly on a canvas or something, but AFAIK WPF doesn't let you access pixel data directly (at least not easily).
Upvotes: 2
Views: 1457
Reputation: 5325
To achieve this your going to have to create your own rectangle user control to allow the user to create/resize a rectangle. Then I would create a CroppedBitmap of the image in the rectangle portion
Cropped Bitmap MSDN
Stackoverflow example
No, no, no @Mark, You dont turn the CroppedBitmap into a UserControl. You create a USerControl that exposed the CroppedBitmap. Basically, you create a UserControl with the following DependencyProperties
Then as soon as any of these properties your DP callback will do a RenderTargetBitmap Crop of the new region.
Upvotes: 2