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

2

2

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?

Acadian answered 10/12, 2013 at 10:12 Comment(0)
S
2

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.

Schilt answered 10/12, 2013 at 13:19 Comment(1)
as you see. i was tried convert byte[] to bitmap and save to local so when i excute convert step throw exception。Acadian
A
0

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.

Acadian answered 11/12, 2013 at 5:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.