Windows 8 C# - thumbnails from iPhone

1

I am working on an application for working with photos for Windows 8 Metro on C#. And now I'm faced with a strange problem.

First, I select the file over PickSingleFileAsync, then trying to get a thumbnail via GetThumbnailAsync:

FileOpenPicker openPicker = new FileOpenPicker ();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add (". jpg");
openPicker.FileTypeFilter.Add (". jpeg");
openPicker.FileTypeFilter.Add (". png");
StorageFile file = await openPicker.PickSingleFileAsync ();
if (file! = null)
{
    BitmapImage bitmapImage = new BitmapImage ();
    var thumb = await file.GetThumbnailAsync (ThumbnailMode.PicturesView, 150, ThumbnailOptions.UseCurrentScale);
    if (thumb! = null) bitmapImage.SetSource (thumb);
}

This code is executed for files on my HDD or for any MTP-devices (tested camera and Android Tablet), but not for the iPhone. This part

var thumb = await file.GetThumbnailAsync (ThumbnailMode.PicturesView, 150, ThumbnailOptions.UseCurrentScale);

Performed for about 30 seconds, and returns null.

This code

BitmapImage bitmapImage = new BitmapImage ();
var stream = await file.OpenAsync (FileAccessMode.Read);
if (stream! = null) bitmapImage.SetSource (stream);

However, this is a complete picture, and I need a thumbnail. I tried to get it by changing the image size.

public static async Task <InMemoryRandomAccessStream> Resize (StorageFile file, uint height, uint width)
{
    var fileStream = await file.OpenAsync (FileAccessMode.Read);
    BitmapDecoder decoder = await BitmapDecoder.CreateAsync (fileStream);
    InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream ();
    BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync (ras, decoder);
    enc.BitmapTransform.ScaledHeight = height;
    enc.BitmapTransform.ScaledWidth = width;
    await enc.FlushAsync ();
    ras.Seek (0);
    return ras;
}

And there

BitmapDecoder decoder = await BitmapDecoder.CreateAsync (fileStream);

Exception "The image cannot be decoded" occurs with code 0x88982F61.

FileOpenPicker also does not display thumbnail images on the iPhone. But standart Photos app for Metro shows all photos on iPhone without problems.

And this leads me to 2 question:

  1. Does anyone have any suggestions to fix this problem?
  2. Maybe, is there a function to retrieve all the thumbnails from device?
c#
iphone
windows-8
microsoft-metro
thumbnails
asked on Stack Overflow Oct 15, 2012 by Nikita

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0