C#

  1. public partial class PhontosAndCameras : PhoneApplicationPage 
  2.     { 
  3.         CameraCaptureTask camera=new CameraCaptureTask(); 
  4.         PhotoChooserTask photo=new PhotoChooserTask(); 
  5.  
  6.         public PhontosAndCameras() 
  7.         { 
  8.             InitializeComponent(); 
  9.              
  10.             camera.Completed += new EventHandler<PhotoResult>(photo_Completed); 
  11.             photo.Completed += new EventHandler<PhotoResult>(photo_Completed); 
  12.         } 
  13.  
  14.         void photo_Completed(object sender, PhotoResult e) 
  15.         { 
  16.             BitmapImage bitmap = new BitmapImage(); 
  17.             bitmap.SetSource(e.ChosenPhoto); 
  18.             p_w_picpath1.Source = bitmap; 
  19.             path.Text = e.OriginalFileName; 
  20.         } 
  21.   
  22.  
  23.         private void Button_Click(object sender, RoutedEventArgs e) 
  24.         { 
  25.             camera.Show(); 
  26.         } 
  27.  
  28.         private void Button_Click_1(object sender, RoutedEventArgs e) 
  29.         { 
  30.             photo.ShowCamera = true
  31.             photo.Show(); 
  32.         } 
  33.     } 

XAML

  1. <Grid x:Name="LayoutRoot" Background="Transparent"> 
  2.         <Grid.RowDefinitions> 
  3.             <RowDefinition Height="Auto"/> 
  4.             <RowDefinition Height="Auto"/> 
  5.             <RowDefinition Height="Auto"/> 
  6.             <RowDefinition Height="Auto"/> 
  7.         </Grid.RowDefinitions> 
  8.         <TextBlock  Name="path" Text="显示路径"></TextBlock> 
  9.         <Image  Name="p_w_picpath1" Grid.Row="1" ></Image> 
  10.         <Button Content="拍照" Grid.Row="2" Width="200" Click="Button_Click"></Button> 
  11.         <Button Content="选择照片" Grid.Row="3" Width="200" Click="Button_Click_1"></Button> 
  12.     </Grid>