There are many ways to do it actually, each with some pros and cons.
WriteableBitmapEx
seems like a popular solution. I have a similar implementation inWinRT XAML Toolkit
. Both are essentially copying blocks of pixels from a full image bitmap. It might not be the fastest way, but if you'd want to get an out of the box solution - it is one that is easy to use. You need to copy the pixels, so you are not optimizing for memory use at the time of the operation and so might run out of memory on very large images quicker. You can recrop easily though end save the results to an image file if you want.- The
BitmapDecoder
solution Jan recommended is one I often use as it is part of the platform, written in native code and possibly highly optimized and you don't copy the pixels, but if you want to recrop - you'll need to decode the image again. - Xyroid's suggestion with
Clip
geometry is a quick display-only solution. You don't actually modify the bitmap in memory - you simply display a region of it on the screen. You need then to keep the entire image in memory and if you want to save it - you still need to update the bitmap to save it - by using either one of the first two solutions or maybe useRenderTargetBitmap.Render()
if screen resolution is enough for you. It should be very quick though to update the crop region displayed on the screen for quick preview. - Another one is with a
Rectangle
filled with anImageBrush
where you can apply aTransform
and specify theRectangle
size to control cropping. It is fairly similar to theClip
solution only instead of clipping an image and in this case you actually have to use theTramsform
(which you can also do on aClip
-RectangleGeometry
). For quick updates - using aTransform
might actually be a bit faster than updating the geometry and also supports scaling and rotations.