C# で Windows 8 Metro の写真を操作するためのアプリケーションに取り組んでいます。そして今、私は奇妙な問題に直面しています。
まず、PickSingleFileAsync でファイルを選択し、次に 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);
}
このコードは、HDD 上のファイルまたは任意の MTP デバイス (テスト済みのカメラと Android タブレット) に対して実行されますが、iPhone に対しては実行されません。この部分
var thumb = await file.GetThumbnailAsync (ThumbnailMode.PicturesView, 150, ThumbnailOptions.UseCurrentScale);
約 30 秒間実行され、null が返されます。
このコード
BitmapImage bitmapImage = new BitmapImage ();
var stream = await file.OpenAsync (FileAccessMode.Read);
if (stream! = null) bitmapImage.SetSource (stream);
ただし、これは全体像であり、サムネイルが必要です。画像サイズを変えてみました。
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;
}
そしてそこに
BitmapDecoder decoder = await BitmapDecoder.CreateAsync (fileStream);
コード 0x88982F61 で例外「画像をデコードできません」が発生します。
FileOpenPicker も、iPhone でサムネイル画像を表示しません。しかし、Metro の標準の写真アプリでは、iPhone 上のすべての写真が問題なく表示されます。
そして、これは私を2つの質問に導きます:
- この問題を解決するための提案はありますか?
- おそらく、デバイスからすべてのサムネイルを取得する機能はありますか?