0
如何將圖片從我的應用程序保存到WP8.1運行庫應用程序中的圖片庫?任何有用的鏈接或代碼片段?如何將圖片保存在wp8.1的圖片庫中
如何將圖片從我的應用程序保存到WP8.1運行庫應用程序中的圖片庫?任何有用的鏈接或代碼片段?如何將圖片保存在wp8.1的圖片庫中
包括這首
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Graphics.Imaging;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
using System.IO;
然後在構造函數中
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
然後複製聲明
BitmapImage bit = new BitmapImage();
string filename;
CameraCaptureTask cameraCaptureTask;
粘貼此
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show(e.ChosenPhoto.Length.ToString());
bit.SetSource(e.ChosenPhoto);
myImage.Source = bit;
filename = "WP_" + Convert.ToString(DateTime.Now.Ticks) + ".jpg";
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isolatedStorage.FileExists(filename))
isolatedStorage.DeleteFile(filename);
IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(filename);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
fileStream.Close();
}
//Code to display the photo on the page in an image control named myImage.
//System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
//bmp.SetSource(e.ChosenPhoto);
//myImage.Source = bmp;
}
}
然後調用這個methhod在以往任何時候億郵想要
cameraCaptureTask.Show();
要添加到媒體庫做這個副本低於
var library = new MediaLibrary();
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filename, FileMode.Open, FileAccess.ReadWrite);
var pic = library.SavePicture(filename, fileStream);
}
給予代碼