How to control when image data is loaded into memory in Windows Store apps?

When creating an image in the Windows Store application, how do you control when data is read from disk?

In WPF, you can control when an image has been read from disk using BitmapCacheOptions . BitmapCacheOptions.OnDemand will delay reading data from disk until image data is needed. There were several drawbacks:

  • IO costs often appear as user interface delays;
  • If the stream was used as an image source, then the stream could not be closed;
  • If a file was used as the image source, the file was locked.

To solve this problem, you can use BitmapCacheOptions.OnLoad to read the image into memory immediately.

How do you control when image data is loaded into memory in Windows Store apps?

The WPF code will look something like this:

 var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.UriSource = path; bitmapImage.EndInit(); bitmapImage.Freeze(); 

Edit - Additional Information

WPA shows that getting an 8.8 MB image per screen costs ~ 330 ms. Of this, 170 ms was spent on the IO file (including 37 ms for the antivirus to scan the file), and 160 ms was spent on WIC decoding.

Any ideas how to control when the file I / O process occurs or how to initiate WIC decoding? Right click and open in new tab to see full size (Right click and open in a new tab to see full size)

+4
source share
1 answer

For Windows Store apps, I suggest exploring AccessCache APIs - http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.aspx

In particular, the StorageApplicationPermissions class. With it, you can add various storage items for access.

Take a look at FilePickerSampl e (or FileAccessSample ) for more information on how to use it.

0
source

Source: https://habr.com/ru/post/1500341/


All Articles