Search code examples
windows-phone-8lockscreen

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


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?


Solution

  • 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.