1

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
  • 1
    if you could post exception log to the answer it would really help us :) Commented Dec 21, 2014 at 9:56

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@user3555472 I see you've unaccepted the answer... what happened?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.