Hi,
I am using the Windows.Media.Import api to retrieve images from a mobile device connected over USB (using MTP) and showing them in a grouped GridView.
The code to retrieve thumbnails and show them is the following:
private void OnGridViewContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (args.Phase == 0)
{
args.RegisterUpdateCallback(ShowThumbnail);
args.Handled = false;
}
}
private async void ShowThumbnail(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (args.Phase == 1)
{
var photoItemProps = args.Item as PhotoItemProperties;
try
{
var thumbnailStream = await photoItemProps.ImportableItem.Thumbnail.OpenReadAsync();
if (thumbnailStream != null)
{
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(thumbnailStream);
var templateRoot = args.ItemContainer.ContentTemplateRoot as Grid;
var image = templateRoot.Children[0] as Image;
image.Source = bitmapImage;
}
}
catch (Exception e)
{ }
}
}
Depending on the connected device, I am seeing 2 type of exceptions coming up when loading the thumbnails of the images:
The System.Exception happens inside the Thumbnail.OpenReadAsync call and occurs when the device contains a lot of images (+3000 in my case, where most of them are music thumbnails generated by the VLC player on android).
The exception message is: Exception from HRESULT: 0x80042010The System.OutOfMemoryException also happens inside OpenReadAsync and occurs on an older (a bit slower) device with just 200 pictures but lots of .webp images.
The exception message is: Insufficient memory to continue the execution of the program.
In both cases the exceptions don't seem to affect my app but in addition to the exception 2 other things don't seem to be correct:
In case of the +3000 pictures device all thumbnails come out well but scrolling in the GridView is really slow (unusable) when I scroll fast, e.g. by dragging the scrollbar handle. Scrolling row per row is acceptable.
In case of the older (slower) device most of the retrieved thumbnails are fixed placeholder thumbnails and not the real images. I think that this is an issue in the api implementation since I also see the same fixed placeholder images coming up in Microsoft's Windows Photo app when doing an import there.
So, my questions:
Are the exceptions normal?
Is there a reason why UWP apps would get placeholder thumbnails?
What methods can be used to make a grouped GridView more responsive when attached to a mobile device?
Jos