2014-11-01 90 views

回答

0

包括这首

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); 

    } 
给予代码