Hi.
This code works for me with 920 and 820(dev version):
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using testcamera.Resources;
using System.Diagnostics;
using Microsoft.Devices;
using System.Windows.Media;
namespace testcamera
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
Microsoft.Devices.PhotoCamera cam = null;
VideoBrush viewfinderBrush;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
Debugger.Log(1, "Info", "\nOnNavigatedTo Event fired\n");
try
{
viewfinderBrush = new VideoBrush();
canvas.Background = viewfinderBrush;
CameraButtons.ShutterKeyPressed +=ShutterButton_Click;
cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
cam.Initialized += cam_Initialized;
cam.CaptureStarted += (s,ee)=>{ Debugger.Log(1, "Info", "CaptureStarted event fired\n");};
cam.CaptureCompleted += (s,ee)=>{ Debugger.Log(1, "Info", "CaptureCompleted event fired\n");};
cam.CaptureImageAvailable += (s,ee)=>{ Debugger.Log(1, "Info", "CaptureImageAvailable event fired\n");};
cam.CaptureThumbnailAvailable += (s, ee) => { Debugger.Log(1, "Info", "CaptureThumbnailAvailable event fired\n"); };
viewfinderBrush.SetSource(cam);
Debugger.Log(1, "Info", "\nSource set\n");
}
catch (Exception excep)
{
Debugger.Log(1, "Info", "\nException in OnNavigatedTo: " + excep.Message + "\n");
}
}
private void ShutterButton_Click(object sender, EventArgs e)
{
try
{
cam.CaptureImage();
Debugger.Log(1, "Info", "CaptureImage method called\n");
}
catch (Exception ex)
{
Debugger.Log(1, "Info", "CaptureImage exception: " + ex.Message + "\n");
}
}
void cam_Initialized(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e)
{
if (e.Succeeded)
{
Debugger.Log(1, "Info", "Camera initialized\n");
}
else
{
Debugger.Log(1, "Info", "\nFailed to initialize. Message: " + e.Exception.Message + ":** " + e.Exception.StackTrace + "\n");
}
}
}
}
Code:
<phone:PhoneApplicationPage
x:Class="testcamera.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Canvas x:Name="canvas"></Canvas>
</Grid>
</phone:PhoneApplicationPage>
why your ShutterButton_Click use a RoutedEventArgs ?