1

私のアプリでは、ユーザーはデバイスのメモリ、つまりタブレットのメモリまたはデスクトップのローカル ドライブからプロファイルの写真を設定し、それをサーバーにアップロードできます。ユーザーが1枚の写真を選択してプロフィール写真として設定できるようにファイルピッカーを使用しましたが、問題は写真がImage要素に貼り付けられていないことです。私のコード:

 private async void filePicker()
        {
            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)
            {

                String filePath = file.Path;
                System.Diagnostics.Debug.WriteLine(filePath);

                Uri uri = new Uri(filePath, UriKind.Relative);
                profilePicture.Source = new BitmapImage(uri);
            }
        }

        internal bool EnsureUnsnapped()
        {
            // FilePicker APIs will not work if the application is in a snapped state.
            // If an app wants to show a FilePicker while snapped, it must attempt to unsnap first
            bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) || ApplicationView.TryUnsnap());
            if (!unsnapped)
            {
                //NotifyUser("Cannot unsnap the sample.", NotifyType.StatusMessage);
            }

            return unsnapped;
        }

私が取得しているファイルパスはこれです

filePath=C:\Users\Prateek\Pictures\IMG_0137.JPG

何がうまくいかなかったのかわかりません。

4

2 に答える 2