缩放图像时出现内存不足异常 [英] Out of memory Exception while scaling image

查看:121
本文介绍了缩放图像时出现内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new on Windows phone development. I am scaling an image, first time it scale image good but when I am choose another picture and implement scale on image so I get a System.OutOfMemoryException. On this line

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();

我该如何解决?

推荐答案

您正在将图像缩放500%.这真的是您想要的吗?此操作后,该图像或第二个图像可能太大.

You are scaling the image by 500%. Is this really what you want? The image or the second image could be too big after this operation.

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

Values between 0 and 1 decrease the width of the scaled object; values greater than 1 increase the width of the scaled object. A value of 1 indicates that the object is not scaled in the x-direction.

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

Negative values flip the scaled object horizontally. Values between 0 and -1 flip the scale object and decrease its width. Values less than -1 flip the object and increase its width. A value of -1 flips the scaled object but does not change its horizontal size.

ScaleTransform类

这篇关于缩放图像时出现内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆