none
WP 8.1 SL项目在Win10m中调用系统相册问题 RRS feed

  • 问题

  • PhotoChooserTask pct = new PhotoChooserTask();
            private void ModifyImage()
            {
                pct.PixelWidth = 300;
                pct.PixelHeight = 300;
                pct.ShowCamera = true;
                pct.Completed += pct_Completed;
                pct.Show();
            }

    手机系统 Windows 10 Mobile Insider Preview Build 10536

    新建WP 8.0 SL项目,执行如上代码,可以成功唤起相册,升级项目到WP 8.1 SL,则出现异常无法正常启动相册。

    2015年9月21日 12:27

答案

  • 你好,

    根据你的异常信息,可以看出是线程问题,用PhotoChooserTask唤起相册时,代码没有运行在UI线程上,你可以将代码修改成我下面的代码:

    Dispatcher.BeginInvoke(new Action(()=> {
                    ModifyImage();
                }));

    这边我的建议是,PhotoChooserTask在windows phone8.1 和universal windows application中是不能用了,8.1 SL项目只是一个过渡的方式,最好还是使用FileOpenPicker去唤起相册,我用FileOpenPicker测试了一下,没有问题,你可以试一下。

    private async void Button_Click(object sender, RoutedEventArgs e)
            {
                //ModifyImage();
                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)
                {
                    // Application now has read/write access to the picked file
                    MessageBox.Show(file.Name);
                }
                else
                {
                    MessageBox.Show("Failed");
                }
            }
    

    更多关于FileOpenPicker的信息,你可以参考微软的官方文档:https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.fileopenpicker.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年9月24日 2:08
    版主