【发布时间】:2014-10-25 07:41:23
【问题描述】:
我有一张图片和 9 张小图片。我想将图像裁剪为 9 块并在 9 个小图像上显示它们。我使用的是 Windows Phone 8。你能要我吗?
谢谢
【问题讨论】:
-
@IvanCrojachKaračić:谢谢,但我不知道什么类型的 sourceBitmap ???
标签: windows-phone-8
我有一张图片和 9 张小图片。我想将图像裁剪为 9 块并在 9 个小图像上显示它们。我使用的是 Windows Phone 8。你能要我吗?
谢谢
【问题讨论】:
标签: windows-phone-8
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(其实很容易编程,只需要一点代数)
【讨论】: