Windows phone 7 将图像从图像控件保存到windows phone 7中的gallery
我在图像控件中有一个图像,如下所示:Windows phone 7 将图像从图像控件保存到windows phone 7中的gallery,windows-phone-7,image-gallery,Windows Phone 7,Image Gallery,我在图像控件中有一个图像,如下所示: <Image x:name="myImg" Source="Images/MyImg.png" /> 如何将此图像保存到图像库中,以便通过转到“库”文件夹进行查看 我尝试了不同的代码,但无法保存。请帮我做这个 编辑: 我在列表框中控制了图像。我正在将列表框与来自web服务的IList绑定 因此,在绑定图像后,如果用户想要保存图像,他可以保存他想要保存的特定图像 那么,我如何才能保存该特定图像 提前谢谢 有一篇优秀的MSDN文章描述了这一场景
<Image x:name="myImg" Source="Images/MyImg.png" />
如何将此图像保存到图像库中,以便通过转到“库”文件夹进行查看
我尝试了不同的代码,但无法保存。请帮我做这个
编辑:
我在列表框中控制了图像。我正在将列表框与来自web服务的IList绑定
因此,在绑定图像后,如果用户想要保存图像,他可以保存他想要保存的特定图像
那么,我如何才能保存该特定图像
提前谢谢 有一篇优秀的MSDN文章描述了这一场景: 顺便说一句,在和上搜索
windows phone将图像保存到媒体库时,它也是第一个搜索结果链接
您是否尝试过遵循本指南,如果是,您有什么问题
保存它的基本代码:
private void btnSave_Click(object sender, RoutedEventArgs e)
{
// Create a file name for the JPEG file in isolated storage.
String tempJPEG = "TempJPEG";
// Create a virtual store and file stream. Check for duplicate tempJPEG files.
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(tempJPEG))
{
myStore.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
// Create a stream out of the sample JPEG file.
// For [Application Name] in the URI, use the project name that you entered
// in the previous steps. Also, TestImage.jpg is an example;
// you must enter your JPEG file name if it is different.
StreamResourceInfo sri = null;
Uri uri = new Uri("[Application Name];component/TestImage.jpg", UriKind.Relative);
sri = Application.GetResourceStream(uri);
// Create a new WriteableBitmap object and set it to the JPEG stream.
BitmapImage bitmap = new BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode the WriteableBitmap object to a JPEG stream.
wb.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
myFileStream.Close();
// Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
MediaLibrary library = new MediaLibrary();
if (radioButtonCameraRoll.IsChecked == true)
{
// Save the image to the camera roll album.
Picture pic = library.SavePictureToCameraRoll("SavedPicture.jpg", myFileStream);
MessageBox.Show("Image saved to camera roll album");
}
else
{
// Save the image to the saved pictures album.
Picture pic = library.SavePicture("SavedPicture.jpg", myFileStream);
MessageBox.Show("Image saved to saved pictures album");
}
myFileStream.Close();
}
谢谢马格纳斯的回复。我的图像控件是动态绑定的,它位于ListBox控件中。因此,我无法获取使用您的代码行的URL(即:Uri Uri=new Uri(“[Application Name];component/TestImage.jpg”,UriKind.Relative);),因此我希望在绑定图像后保存图像。我该怎么做?你在问题中根本没有提到这一点。请用这些信息更新您的问题。