裁剪图像的特定部分

时间:2014-03-29 04:35:48

标签: windows-phone-8

我正在构建一个Windows Phone 8相机应用程序。拍完照片后,我想让用户选择裁剪图像的特定部分。就像图像中有一些特定的对象一样,当选择裁剪选项时,它应该突出显示或勾勒出图像的特定部分,并且它应该能够裁剪它,而不是手动裁剪它。

任何具体的方法吗?。

提前致谢。

1 个答案:

答案 0 :(得分:0)

一种方法是创建WriteableBitmap并将TranslateTransform原始图片放入WritableBitmap。像::

之类的东西
Image workImage = new Image { Source = originalImage, Width = originalWidth, Height = originalHeight };

WriteableBitmap writeableBitmap = new WriteableBitmap(newWidth, newHeight);
writeableBitmap.Render(temporaryImage, new TranslateTransform { X = (originalWidth – newWidth) / -2, Y = (originalHeight – newHEight) / -2 });
writeableBitmap.Invalidate();

//... or some other stream
Stream newImageStream = new MemoryStream();
//set whatever quality settings you like if 75 is no good
writeableBitmap.SaveJpeg(newImageStream, newWidth, newHeight, 0, 75);

// TODO: do something with newImageStream