我是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(图像)保存在相机胶卷中。我做了一点研究,发现了
MediaLibrary.SavePictureToCameraRoll方法
这种方法有助于
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.
如何在代码中实现此方法?
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);
}