WP8 BitmapImage和分辨率限制 [英] WP8 BitmapImage and resolution limitation

查看:63
本文介绍了WP8 BitmapImage和分辨率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我正在尝试将我的应用程序之一转换为WP8.在该应用程序中,我拍摄照片,然后在上面应用一些文本.在WP7中将拍摄的照片加载到BitmapImage中时,会自动调整其大小(因为限制为2000x2000),但是现在BitmapImage 完全以8mpx分辨率加载时,如果将其放入WriteableBitmap中,然后尝试在图像上呈现一些控件,则会产生不良行为.

I am trying to convert one of my application to WP8. In that application I take photo and then applying some texts on it. In WP7  when loading taken photo into BitmapImage automatically re-sized it (as the limitation was 2000x2000), but now BitmapImage loads in full 8mpx resolution which produce bad behavior when I put this into WriteableBitmap and then trying to render some controls over the image.

这里我从隔离存储中加载图像

Here I load image from isolated storage

BitmapImage bi = new BitmapImage();
            bi.CreateOptions = BitmapCreateOptions.None;

            using (IsolatedStorageFile _file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs = _file.OpenFile(Global.ImageOriginalName, System.IO.FileMode.Open))
                {
                    bi.SetSource(fs);
                }
            }
            
            WriteableBitmap bmp = new WriteableBitmap(bi);

接下来,我通过创建一些控件并最后进行一些操作

next I do some manipulation with creating some controls and at the end

bmp.Render(画布,变换);

bmp.Render(canvas, transform);

bmp.Invalidate();

bmp.Invalidate();

但是Render函数无一例外地杀死了我的应用程序.我什至无法在调试器中捕获它.我认为这是因为BitmapImage以全分辨率加载.

But Render function just killed my app without any exception. I even unable to catch it in debugger. I think this is because BitmapImage loaded in full resolution.

BitmapImage上有关于WP8的任何文档吗?当前关于WP8的文档非常糟糕.寻找任何有用的东西总是要花费我几个小时.

It there are any documentation on BitmapImage for WP8 ? Currently documentation for WP8 is very awful. It always tooks me hours to find anything useful.

谢谢.

推荐答案

你好!

您要在此处加载的原始图像有多少(以像素为单位)?我猜你内存不足了.

how large is the original image (in pixels) that you are trying to load here? I am guessing you are running out of memory.

这里是一些背景:

在加载大图像时,BitmapImage类将它们缩小到可以显示的最大纹理大小,而无需裁剪.在WP7中为2048x2048,在WP8中为4096x4096.

When loading huge images, the BitmapImage class downscales them to the maximum texture size that can be displayed without clipping. In WP7 this was 2048x2048, in WP8 this has been increased to 4096x4096.

该大小的位图将需要4096 * 4096 * 4字节= 64MB的内存,仅用于解码.加上应用程序的额外开销,您可能会耗尽应用程序的内存上限.

A bitmap of that size will take 4096*4096*4 bytes = 64MB of memory, just to decode. With the additional overhead from your app you are probably hitting the memory cap for apps.

要解决此问题,可以在BitmapImage上设置DecodePixelHeight/Width属性,以控制实际的解码大小.因此,您可以将其设置回2048(如WP7),或者将其设置为较小的值以进一步减少工作集.

To resolve this you can set the DecodePixelHeight/Width properties on the BitmapImage to control the actual decode size. So you could set it back to 2048 (as in WP7) or to a smaller value to reduce workingset further.

未在(托管代码)调试器中捕获此错误的原因可能是因为内存不足发生在代表您在OS中进行本机代码操作期间(调用堆栈中没有代码).尝试在中切换到本机代码调试 项目设置,看看是否可以捕获到此.

The reason you are not catching this in the (managed code) debugger may be because the out-of-memory happens during a native code operation in the OS on your behalf (without your code on the callstack). Try switching to native code debugging in the project settings to see if you can catch this.

希望这会有所帮助.

谢谢,斯蒂芬·威克

Microsoft Windows Phone开发人员平台

Microsoft Windows Phone Developer Platform


这篇关于WP8 BitmapImage和分辨率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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