【问题标题】:Out of memory Exception while scaling image缩放图像时出现内存不足异常
【发布时间】:2015-02-19 16:50:15
【问题描述】:

我是 Windows 手机开发的新手。我正在缩放图像,第一次缩放图像很好,但是当我选择另一张图片并在图像上实现缩放时,我得到了 System.OutOfMemoryException。在这条线上

ScaleTransform t = new ScaleTransform() { ScaleX = 5, ScaleY = 5 };

我尝试缩放图像的代码。

Image uiElement = new Image() { Source = blurImage };
ScaleTransform t = new ScaleTransform() { ScaleX = 5, ScaleY = 5 };

WriteableBitmap writeableBitmap = new WriteableBitmap(uiElement, t);

using (MemoryStream ms = new MemoryStream())
{
    writeableBitmap.SaveJpeg(ms, (int)blurImage.PixelWidth, (int)blurImage.PixelHeight, 0, 100);                      
    bmp.SetSource(ms);
    imgholder.Source = null;
    imgholder.Source = bmp;
    ms.Dispose();
}
t = null;
writeableBitmap = null;
uiElement.Source = null;
uiElement = null;
GC.Collect();

我该如何解决?

【问题讨论】:

  • 如果您可以将异常日志发布到答案中,它真的会帮助我们:)

标签: c# windows-phone-8 memory-management windows-phone-8.1


【解决方案1】:

您将图像缩放 500%。这真的是你想要的吗?此操作后图像或第二张图像可能太大。

0 到 1 之间的值会减小缩放对象的宽度;大于 1 的值会增加缩放对象的宽度。值为 1 表示对象未在 x 方向上缩放。

负值水平翻转缩放的对象。介于 0 和 -1 之间的值会翻转缩放对象并减小其宽度。小于 -1 的值会翻转对象并增加其宽度。值为 -1 会翻转缩放的对象,但不会改变其水平大小。

ScaleTransform Class

【讨论】:

  • 非常感谢您的解释,它真的帮助了我。 :)
  • @user3555472 我看到你没有接受答案......发生了什么?
猜你喜欢
  • 2011-06-18
  • 1970-01-01
  • 2016-09-02
  • 1970-01-01
  • 1970-01-01
  • 2014-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多