2012-06-17 31 views
1

實際上,我使用相機加載VideoBrush以使用Windows Phone 7.1中的PhotoCamera選項拍攝對象的快照。相機正在花時間完成Windows手機中的任務

一旦拍攝快照,我將CaptureImageAvailable事件中的e.ImageSteam設置爲ImageBrush源。

一旦我拍攝了快照,在WindowsPhone中調用CaptureImageAvailable或CaptureCompleted事件需要一些時間。爲什麼這種情況?

我是否需要寫點新東西來解決這個問題?

+0

可以爲您發佈編碼你的嘗試,這將有助於巧妙地回答你 – Ponmalar

+0

你可以看看下面的msdn文檔... http://msdn.microsoft.com/en-us/library/hh202956(v = vs.92).aspx爲示例 –

回答

0

對於拍照,然後選擇照片,只要你能遵循這一點,

MainPage.xaml中:

<Button Content="Take Photo" Height="72" HorizontalAlignment="Left" Margin="0,10,0,0" Click="btntakephoto_Click" Name="btntakephoto" VerticalAlignment="Top" Width="456" /> 
      <Image Height="431" HorizontalAlignment="Left" Margin="10,92,0,0" Name="imgphoto" Stretch="Fill" VerticalAlignment="Top" Width="440" /> 
      <Button Content="Choose Photo" Height="72" HorizontalAlignment="Left" Margin="0,529,0,0" Click="btnchoosephoto_Click" Name="btnchoosephoto" VerticalAlignment="Top" Width="450" /> 

MainPage.cs

namespace TakePicture 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     CameraCaptureTask camera = new CameraCaptureTask(); 
     PhotoChooserTask choosephoto = new PhotoChooserTask(); 

     public MainPage() 
     { 
      InitializeComponent(); 
      camera.Completed += new EventHandler<PhotoResult>(task_Completed); 
      choosephoto.Completed += new EventHandler<PhotoResult>(task_Completed); 
     } 

     private void btntakephoto_Click(object sender, RoutedEventArgs e) 
     { 
      camera.Show(); 
     } 

     private void btnchoosephoto_Click(object sender, RoutedEventArgs e) 
     { 
      choosephoto.Show(); 
     } 

     private string SaveImageToLocalStorage(WriteableBitmap image, string imageFileName) 
     { 

      if (image == null) 
      { 
       throw new ArgumentNullException("imageBytes"); 
      } 
      try 
      { 
       var isoFile = IsolatedStorageFile.GetUserStoreForApplication(); 

       if (!isoFile.DirectoryExists("MyPhotos")) 
       { 
        isoFile.CreateDirectory("MyPhotos"); 
       } 

       string filePath = System.IO.Path.Combine("/" + "MyPhotos" + "/", imageFileName); 
       using (var stream = isoFile.CreateFile(filePath)) 
       { 
        image.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 0, 80); 
       } 

       return new Uri(filePath, UriKind.Relative).ToString(); 
      } 
      catch (Exception) 
      { 
       //TODO: log or do something else 
       throw; 
      } 
     } 

     void task_Completed(object sender, PhotoResult e) 
     { 
      if (e.ChosenPhoto != null) 
      { 
       if (e.TaskResult == TaskResult.OK) 
       { 
        try 
        { 
         string imagePathOrContent = string.Empty; 
         WriteableBitmap image = PictureDecoder.DecodeJpeg(e.ChosenPhoto); 
         imgphoto.Source = image; 
         imagePathOrContent = this.SaveImageToLocalStorage(image, System.IO.Path.GetFileName(e.OriginalFileName)); 
        } 
        catch (Exception) 
        { 
        } 
       } 
      } 
     } 
    } 
} 
+0

我不想使用現有的API在WindowsPhone中...我想使用Accept和Retake按鈕來創建自己的Camera應用程序,就像Windows Phone相機一樣......這就是爲什麼我使用PhotoCamera選項的原因。 –