Windows Phone 8 ImageSource 无法序列化共享图像时出错

编程入门 行业动态 更新时间:2024-10-25 13:22:58
本文介绍了Windows Phone 8 ImageSource 无法序列化共享图像时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想分享一张图片.我得到了一个图片对象,并且正在从中获取路径.当我调用 ShareMediaTask 时,它会抛出以下错误:

i am trying to share an image. I got a picture object and am getting the path from it. When I'm calling the ShareMediaTask it throw following error:

System.Windows.Media.ImageSource 无法序列化.

我仍然可以分享图片,但分享结束后应用崩溃了.

I am still able to share the image, but the app crashes when returning from sharing.

这是我的代码:

        PictureModel picture = Singleton.Instance.BearPicture.Model.Images.Where(PictureModel => PictureModel.Bmp.UriSource == (Image_View.Source as BitmapImage).UriSource).FirstOrDefault();


        var task = new ShareMediaTask();


        task.FilePath = picture.Picture.GetPath();

        task.Show();

我的图片模型如下所示:

My PictureModel looks like this:

 public class PictureModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string _uri;
    public string Uri
    {
        get { return _uri; }
        set
        {
            if (value != _uri)
            {
                _uri = value;
                NotifyPropertyChanged("Uri");
            }
        }
    }

    private string _relativePath;
    public string RelativePath
    {
        get { return _relativePath; }
        set
        {
            if (_relativePath != value)
            {
                _relativePath = value;
                NotifyPropertyChanged("RelativePath");
            }
        }
    }

    private BitmapImage _bmp;
    public BitmapImage Bmp
    {
        get { return _bmp; }
        set
        {
            if (value != _bmp)
            {
                _bmp = value;
                NotifyPropertyChanged("Bmp");
            }
        }
    }

    private Picture _picture;
    public Picture Picture
    {
        get { return _picture; }
        set
        {
            if (value != _picture)
            {
                _picture = value;
                NotifyPropertyChanged("Picture");
            }
        }
    }

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

}

这个错误从何而来?我只得到我的图像对象的来源,但我没有用它做任何其他事情.我的图片也是这样保存在媒体库中的:

Where does this error come from? I am only getting the Source of my image object but i am not doing anything else with it. My picture is also saved in the media library like this:

  myFileStream = myStore.OpenFile(fileName, FileMode.Open, FileAccess.Read);
            MediaLibrary library = new MediaLibrary();
            Picture pic = library.SavePicture(fileName, myFileStream);

在 Appstart 上,我在我的 savepicture 文件夹中搜索,以获取图片对象,然后将其保存在我的 PictureModel 中.

On Appstart im searching through my savedpicture folder, to get the picture object, which is then saved in my PictureModel.

感谢任何帮助.提前致谢.罗比德

Any help is appreciated. Thanks in advance. robidd

推荐答案

这可能会有所帮助:windows phone 8 崩溃(WriteableBitmap 不能序列化).请参阅来自 KooKiz 的评论.

This may help: Crashes Back (WriteableBitmap cannot be serialized) windows phone 8. See the comment from KooKiz.

相同的症状,相同的原因.您在某个时候已将 ImageSource 存储在手机状态(可能是 PhoneApplicationService.Current.State 或 IndependentStorageSettings.ApplicationSettings).您必须找到位置!"

"Same symptoms, same cause. You've stored at some point an ImageSource in the phone state (probably PhoneApplicationService.Current.State or IsolatedStorageSettings.ApplicationSettings). You have to find where!"

显然我们可以间接导致这个错误.我遇到了类似的问题,我找到了答案以及您自己的问题.

Apparently we can cause this error indirectly. I'm having a similar problem and I found that answer and also your own question.

希望有帮助.干杯.

这篇关于Windows Phone 8 ImageSource 无法序列化共享图像时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 13:34:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117502.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   序列化   Windows   Phone   ImageSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!