0

我想在连续页面中显示带有图像的项目详细信息,并使用加载的图像bitmapimage.setsource(new meorystream(byte[]value))

导航页面时,会发生异常,例如"Insufficient memory to continue the execution of the program"在 Windows Phone 8 应用程序上的 C# 中。

我该如何解决这个问题?

4

2 回答 2

0

如果可以的话,考虑降低图像质量

于 2013-07-05T07:44:37.730 回答
0

我碰巧有你需要的代码,我想:

 public static MemoryStream CompressImageStream(Stream inputStream)
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.SetSource(inputStream);

            WriteableBitmap wb = new WriteableBitmap(bitmap);

            // Encode WriteableBitmap object to a JPEG stream. 
            MemoryStream targetStream = new MemoryStream();

            try
            {
                Extensions.SaveJpeg(wb, targetStream, 100, 100, 0, 80);
            }
            catch (Exception e)
            {

            }

            targetStream.Position = 0;

            return targetStream;
        }

查看“ Extensions.SaveJpeg(wb, targetStream, 100, 100, 0, 80); ”,它设置了图像尺寸和压缩率。希望这可以帮助。

于 2013-11-14T08:56:16.170 回答