【问题标题】:Save edited image to Camera Roll将编辑后的图像保存到相机胶卷
【发布时间】:2013-11-28 00:41:12
【问题描述】:

我是 C# 新手,正在学习为 Windows Phone 8 进行开发。我正在制作一个图像编辑应用程序。 有没有办法将编辑后的图像保存在相机胶卷中而不是保存的图片中。

使用 PhotoChooserTask 会返回一个 PhotoResult。

    private WriteableBitmap _imageBitmap = null;

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhotoChooserTask chooser = new PhotoChooserTask();
        chooser.Completed += choosenImage;
        chooser.Show();
    }

    private void choosenImage(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK ) { return; }
        _imageBitmap.SetSource(e.ChosenPhoto);
        dummyImage.Source = _thumbImageBitmap;

        //MediaLibrary library = new MediaLibrary();
        //library.SavePictureToCameraRoll(String, Stream);
    }

我想将此 PhotoResult(image) 保存在相机胶卷中。我做了一点研究,发现

MediaLibrary.SavePictureToCameraRoll Method

这个方法有帮助

MediaLibrary.SavePictureToCameraRoll (String, Stream)
Save the specified image Stream as a Picture in the Windows Phone camera roll.

MediaLibrary.SavePictureToCameraRoll (String, Byte[])
Save the specified byte array as a Picture in the Windows Phone camera roll.

如何在我的代码中实现这个方法?

【问题讨论】:

    标签: c# windows-phone-8 xna stream


    【解决方案1】:

    e.ChosenPhoto 已经是一个流,所以你可以这样设置:

    编辑:这应该可以解决使用流两次的问题。您也许可以简单地寻找到流的开头并重用e.ChosenPhoto,但在我回家之前我无法测试它。

    private void choosenImage(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK ) 
        { 
            return;
        }
        Stream theCopy = new Stream();
        e.ChosenPhoto.CopyTo(theCopy);
        e.ChosenPhoto.Seek( 0, SeekOrigin.Begin );
    
        _imageBitmap.SetSource(e.ChosenPhoto);
        dummyImage.Source = _thumbImageBitmap;
    
        MediaLibrary library = new MediaLibrary();
        library.SavePictureToCameraRoll(String, theCopy);
    }
    

    【讨论】:

    • 我试过了,但它给了我错误。 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.ni.dll but was not handled in user code. If there is a handler for this exception, the program may be safely continued 类型的异常............我的代码 = library.SavePictureToCameraRoll("image.jpg", e.ChosenPhoto);
    • 我已经用一些额外的调用更新了这个,可能会解决这个问题。
    猜你喜欢
    • 2011-11-02
    • 2022-01-01
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    相关资源
    最近更新 更多