How to download a high resolution image of Windows Taskagent? [not enough memory]

As you know, only 11.5 MB of memory can be used for the Windows Phone 8 operating agent. I tried to make a dynamic lock screen image in the background job. When I get an image of 480 * 800, it works fine, but when I change it to 768 * 1280, I throw an exception:

Not enough memory

1 pixel cast 4K

So

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

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

When I tried to convert byte [] to 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 a memory exception in the SetSource() method. Anyone have any suggestions on this?

+2
source share
2 answers

I guess the memory is folding.

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

+2
source

just try a few times, I fixed this problem. As you can see, only 11M memory can be used in the taskagent of a Windows phone. I was tring to make a dynamic lock screen background. my coincidence is loading the image on one side and saving it to the local display.

why did the exception go out of memory?

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

the same memory image just throws three times.

, and how to fix it?

when loading an image from the server side. you must immediately save the local isolate storage and clear the memory usage by byte of image []. just set the URL of the image to lock the screen. got a job.

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

everything is good.

0
source

All Articles