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?