how to load high resolution image windows phone taskagent? [out of memory]

这一生的挚爱 提交于 2019-12-30 07:31:49

问题


As we know, it is only 11.5MB memory that can be used in a Windows Phone 8 task agent. I was trying to make dynamic lock screen image in the background task agent. When I get the 480*800 image, it works fine but when I change it to 768*1280 I the exception:

Out of memory

1 pixel cast 4 K

so

(480*800*4)/1024/1024=1.46M

(768*1280*4)/1024/1024 = 3.75M

When I tried to convert a byte[] to a BitmapImage:

public BitmapImage ConvertDownloadStringToStream(byte[] downloadImageBytes)
{
    if (!(downloadImageBytes.Length > 0))
        return null;

    RationImageInfo currentRationInfor = GetBitmapImageWidthByDeveiceRatio();
    BitmapImage convertBitmapImage = new BitmapImage() { DecodePixelWidth =768, DecodePixelHeight = 1280};

    using (MemoryStream imageStream = new MemoryStream(downloadImageBytes))
    {
        convertBitmapImage.SetSource(imageStream);//out of memory        
    }          

    return convertBitmapImage;
}

I get the out of memory exception at SetSource() method. Does anyone have suggestions about this?


回答1:


I'm guessing the memory adds up.

Try saving it to a file, free the variable/resource, than load it from the file using the constructor parameter.




回答2:


just try some many times i has been fix this problem. as you see it was only have 11M memory can be use in windows phone taskagent. i was tring to make dynamic lock screen background. my soluction is download image from sever side and save to local display it.

why got out of memory Exception?

download image Byte[]=>Write to memory=>build writeableBitmap with 768*1280.

same image memory just cast three time .

so how to fix it ?

when you download your image from server side. you should be save to local isolate storage immediately and clear memory useage about the image byte[]. just set the image url to lockscreen . got be work.

download image Byte[]=>Save To local =>clear image byte memory.

everything is fine.



来源:https://stackoverflow.com/questions/20491566/how-to-load-high-resolution-image-windows-phone-taskagent-out-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!