我有一张图片和9张小图片。我想将图像裁剪成9个图像并在9个小图像上显示它们。我使用Windows Phone 8.你能拥有我吗?
谢谢
答案 0 :(得分:1)
sourceBitmap只是另一个WriteableBitmap
例如,假设我们有这个XAML(其中bigImage是我们要裁剪的图像)
<ScrollViewer>
<StackPanel>
<Image x:Name="bigImage" Source="/Assets/AlignmentGrid.png"></Image>
<Image x:Name="cropImage1"></Image>
</StackPanel>
</ScrollViewer>
然后在
背后的代码中using System.Windows.Media.Imaging;
// using WriteableBitmapEx
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// create a WriteableBitmap with the bigImage as its Source
WriteableBitmap wb = new WriteableBitmap((BitmapSource)this.bigImage.Source);
// calculate and crop
WriteableBitmap crop1 = wb.Crop(0, 0, 100, 100);
// set the cropImage1 image to the image that we just crop from the bigger one
this.cropImage1.Source = crop1;
}
如果你想在不使用WriteableBitmapEx的情况下看到一个很好的解决方案(基本上你要编写自己的Crop,它返回一个WriteableBitmap),那么这个网页适合你:
Crop Image Implementation(它实际上很容易编程,只需要一点代数)