问题
I have BitmapImage and I need to crop it to a rectangle of size 200x200. The rectangle should contain the center of the source BitmapImage. The only solution I've founded, CroppedBitmap does not work Windows Phone.
Another solution could be to create a WriteableBitmap and iterate through each pixel but I is there no easier way?
回答1:
I have remembered that I have seen solution for similar issue here:
Split an image into several pieces silverlight windows phone
回答2:
You could use the WriteableBitmapExtension library and use the Crop function, which is pretty easy to use.
The following code loads the content file "img.jpg" and then crops it, keeping just the center 200x200 pixels.
WriteableBitmap wb = new WriteableBitmap(1, 1);
wb = wb.FromContent("img.jpg");
wb = wb.Crop((wb.PixelWidth / 2) - 100, (wb.PixelHeight / 2) - 100, 200, 200);
来源:https://stackoverflow.com/questions/15471554/windows-phone-crop-bitmapimage