【问题标题】:How to crop an image to 9 pieces如何将图像裁剪为 9 块
【发布时间】:2014-10-25 07:41:23
【问题描述】:

我有一张图片和 9 张小图片。我想将图像裁剪为 9 块并在 9 个小图像上显示它们。我使用的是 Windows Phone 8。你能要我吗?

谢谢

【问题讨论】:

标签: windows-phone-8


【解决方案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(其实很容易编程,只需要一点代数)

【讨论】:

  • @Chubosauurus:非常感谢
猜你喜欢
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 2014-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-10
  • 2012-11-16
相关资源
最近更新 更多