【问题标题】:How do you clip an image from the bottom left in WPF?如何在 WPF 中从左下角剪切图像?
【发布时间】:2014-10-12 16:17:28
【问题描述】:

我正在阅读一个很大的位图并且有很多无用的空间。原图高2048,宽1024。

我想从左下角开始裁剪/剪辑图像以进行显示,并在 c# 中显示图像高度为 1047 和宽度为 1024。我尝试过使用 CroppedBitmap,但一直出现越界错误。

(下面的代码显示了一些随机参数,因为我开始输入很多东西来让它工作一点点。)

这给了我错误:

CroppedBitmap cb = new CroppedBitmap((BitmapSource)bitmapImage,
                                     new Int32Rect(2048,0,30,50));

编辑:换句话说,我想去掉图像的上半部分。

【问题讨论】:

    标签: c# wpf


    【解决方案1】:
    CroppedBitmap cb = new CroppedBitmap(
                               bitmapImage,
                               new Int32Rect(0, (int)(bitmapImage.Height/2),
                               (int)bitmapImage.Width, (int)(bitmapImage.Height/2)); 
    

    这将从 bitmapImage 的下半部分创建一个 CroppedBitmap。 Int32Rect 应该描述您要保留的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 2021-04-01
      相关资源
      最近更新 更多