2012-12-19 90 views

回答

2

有內置的發射器在WP7/WP8 &挑肥揀瘦體驗,允許輕鬆拍攝照片或檢索手機圖片庫中的照片。使用內置照片選擇器是獲得默認用戶體驗的最簡單方法。

你可以閱讀有關CameraCaptureTask,允許在MSDN上迅速捕捉圖像@How to use the camera capture task for Windows Phone

你可以閱讀有關PhotChooserTask,允許從MSDN上的手機的照片庫中檢索圖像@How to use the photo chooser task for Windows Phone

如果你想構建更復雜的圖像處理和相機捕獲應用程序,您可以在諾基亞的Advanced photo capturing文章中閱讀有關WP8新API的信息。

2
 // Try the following steps 

     private readonly CameraCaptureTask _cameraCaptureTask; // Declare CameraCaptureTask 

     if (null == _cameraCaptureTask) _cameraCaptureTask = new CameraCaptureTask(); 
     _cameraCaptureTask.Completed += PhotoSelectionTaskCompleted; 

     // In the completed event 

     void PhotoSelectionTaskCompleted(object sender, PhotoResult e) 
     { 
      if (null != e.ChosenPhoto && e.TaskResult == TaskResult.OK) 
      { 
       var image = new BitmapImage(); 
       image.SetSource(e.ChosenPhoto); 
       SaveImageToIsolatedStorage(image,"Image1.jpg"); 

      } 
     } 

     public void SaveImageToIsolatedStorage(BitmapImage image, string fileName) 
     { 
     using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      if (isolatedStorage.FileExists(fileName)) 
       isolatedStorage.DeleteFile(fileName); 

      var fileStream = isolatedStorage.CreateFile(fileName); 
      if (image != null) 
      { 
       var wb = new WriteableBitmap(image); 
       wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100); 
      } 
      fileStream.Close(); 
     } 
    } 
相關問題