Windows Phone - Crop BitmapImage [closed]

徘徊边缘 提交于 2019-12-11 12:48:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!