0

画像を選択した後、簡単な画像ギャラリーで問題が発生しました.Windows 10の別の画面に送信しましたが、完璧に動作しますが、理由は、私のコードは、次のいずれかです。Windows 10 Mobileで画像を読み取るときにエラーが発生しました

XAMLコード:

<Page 
    x:Class="Stop_Diabetes.Pages.Camera" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Stop_Diabetes.Pages" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    Background="#227EC2" Loaded="Page_Loaded"> 

    <Page.Resources> 
     <local:ImageConverter x:Key="imageConverter"/> 
     <DataTemplate x:Key="imageTemplate"> 
      <Grid Width="190" Height="130"> 
       <Image Source="{Binding Path=Thumbnail, 
      Converter={StaticResource imageConverter}}" Tapped="Image_Tapped" 
      Width="200" Height="200"/> 
      </Grid> 
     </DataTemplate> 
     <CollectionViewSource 
     x:Name="picturesSource"/> 
    </Page.Resources> 

    <Grid> 
     <Grid x:Name="stkGallery" Canvas.ZIndex="15" VerticalAlignment="Bottom"> 
      <GridView x:Name="gvPictures" VerticalAlignment="Top" Height="150" ItemsSource="{Binding Source={StaticResource picturesSource}}" ItemTemplate="{StaticResource imageTemplate}" ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"> 
       <GridView.ItemsPanel> 
        <ItemsPanelTemplate> 
         <WrapGrid Orientation="Vertical"></WrapGrid> 
        </ItemsPanelTemplate> 
       </GridView.ItemsPanel> 
      </GridView> 
     </Grid> 
    </Grid> 
</Page> 

C#の重要なコード:

private void Page_Loaded(object sender, RoutedEventArgs e) 
{ 
    List<string> fileTypeFilter = new List<string>(); 
    fileTypeFilter.Add(".jpg"); 
    fileTypeFilter.Add(".jpeg"); 
    fileTypeFilter.Add(".png"); 
    fileTypeFilter.Add(".gif"); 
    fileTypeFilter.Add(".bmp"); 
    //Define thr query to iterate thriugh all the subfolders 
    var pictureQueryOptions = new QueryOptions(CommonFileQuery.OrderByDate, fileTypeFilter); 
    //Read through all the subfolders. 
    pictureQueryOptions.FolderDepth = FolderDepth.Deep; 
    //Apply the query on the PicturesLibrary 
    var pictureQuery = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(pictureQueryOptions); 
    // 
    var picturesInformation = new FileInformationFactory(pictureQuery, ThumbnailMode.PicturesView); 
    picturesSource.Source = picturesInformation.GetVirtualizedFilesVector(); 
} 

private async void Image_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) 
{ 
    Image img = (Image)sender; 
    FileInformation fi = img.DataContext as FileInformation; 
    if (fi != null) 
    { 
     string path = fi.Name; 
     //do something with the path... 

     var pStorage = KnownFolders.PicturesLibrary; 

     StorageFile file = await pStorage.GetFileAsync(path); 

     ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync(); 

     using (var imgStream = await file.OpenAsync(FileAccessMode.Read)) 
     { 
      WriteableBitmap bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height); 
      bitmap.SetSource(imgStream); 

      Frame.Navigate(typeof(Crop), bitmap); 
     } 
    } 
} 

public class ImageConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, string culture) 
    { 
     if (value != null) 
     { 
      var img = (IRandomAccessStream)value; 
      var picture = new BitmapImage(); 
      picture.SetSource(img); 
      return picture; 
     } 
     return DependencyProperty.UnsetValue; 
    } 
    public object ConvertBack(object value, Type targetType, object parameter, string culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

私の問題はここに起こる:

StorageFileファイル=待機するpStorage.GetFileAsync(パス); PCで

私が電話にいるとき、完全に画像を開きますが、それは言う:

メッセージ=「システムは指定されたファイルを見つけることができません\ rをする\ nは。」

イメージが読み込まれても後で開くことができないため、ID、パスなどのさまざまなオプションを試してみたところ、誰もうまくいきません。誰もがWindows 10 Mobileで何を変えなければならないか知っていますか?

これは、多かれ少なかれ、それは現在のコードの結果をどのように見えるべきかです: Example

答えて

1

のFileInfoクラスがそれらを使用しない理由openAsyncとOpenReadAsync方法を持っていますか?ここで

https://msdn.microsoft.com/en-us/library/windows/apps/br207562

https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.bulkaccess.fileinformation.openreadasync

あなたは

using (var imgStream = await fi.OpenReadAsync()) 
+0

:(VARのimgStream =待つfile.OpenAsync(FileAccessMode.Read)) { WriteableBitmapビットマップ=新しいWriteableBitmap((int型)imgProp.Width、(int型)imgProp.Height)を使用しました。 bitmap.SetSource(imgStream); Frame.Navigate(typeof(Crop)、ビットマップ); } でも、開こうとしているファイルを指定する必要があります。 –

0

appxmanifestで有効に機能 "ピクチャライブラリを" いましたか?変更する必要がありますコードですか私はすでにここにそれを使用しています

関連する問題