问题
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 };
My code where I am trying to scale image.
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();
How can I solve it?
回答1:
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.
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.
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 Class
来源:https://stackoverflow.com/questions/27588276/out-of-memory-exception-while-scaling-image