Introduction



Home Screen :

Name of Experiment : Basic Camera Operation

Exp No : IP1

Background : Student should have a basic knowledge of C#.

Summary : After going through this experiment, student should understand how to access the camera device through the code and could able to learn the basic operation on camera.

Learning Objective : To explain the working of camera hardware.

Target

Target Platform : This application is tested on Windows Phone Emulator and Windows Phone (Lumia 800).

Procedure

Source Code


MainPage.xaml

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ExperimentTitle" Text="Exp No:IP1" TextAlignment="Right" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="ApplicationTitle" Text="Basic Camera Operation" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Welcome Page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="101*" />
<RowDefinition Height="506*" />
</Grid.RowDefinitions>
<Button
x:Name="Photo"
Content="Photo"
Height="72"
HorizontalAlignment="Left"
Margin="12,29,0,0"
VerticalAlignment="Top"
Width="160" />
<Image
Grid.Row="1"
Height="306"
HorizontalAlignment="Right"
Margin="0,68,46,0"
Name="Image1"
Stretch="Fill"
VerticalAlignment="Top"
Width="356" />
<Button Content="Show" Height="72" HorizontalAlignment="Left" Margin="227,29,0,0" Name="cmd_show" VerticalAlignment="Top" Width="160" />
</Grid>
</Grid>

Main Page.xaml.cs
using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;

namespace Camera_Test
{
public partial class MainPage : PhoneApplicationPage
{
CameraCaptureTask _mycamera = new CameraCaptureTask();
PhotoChooserTask _myphoto = new PhotoChooserTask();
// Constructor
public MainPage()
{
InitializeComponent();
_mycamera.Completed+=new EventHandler(_mycamera_Completed);
Photo.Click+=new RoutedEventHandler(Photo_Click);
_myphoto.Completed+=new EventHandler(_myphoto_Completed);
cmd_show.Click+=new RoutedEventHandler(cmd_show_Click);


}

void _mycamera_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK) {
Image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
BitmapImage img = new BitmapImage();
img.SetSource(e.ChosenPhoto);
Image1.Source = img;
}
}

void Photo_Click(object sender, RoutedEventArgs e) {
_mycamera.Show();
}
void _myphoto_Completed(object sender,PhotoResult e) {
if (e.TaskResult == TaskResult.OK)
{ ImageBrush myimagebrush = new ImageBrush();
myimagebrush.ImageSource = new BitmapImage(new Uri(e.OriginalFileName, UriKind.Relative));
Image1.Source = new BitmapImage(new Uri(e.OriginalFileName, UriKind.Relative));
BitmapImage img = new BitmapImage();
img.SetSource(e.ChosenPhoto);
Image1.Source = img;
}
}
void cmd_show_Click(object sender, RoutedEventArgs e)
{
_myphoto.Show();
}
}
}

Snapshots







Observation

Observation : After going through this experiment, developer can analyse that camera hardware can be easily controlled by the soft code.

Video Link

For Windows Phone

Download

Right Click Here And Select Save Target For Entire Download :

Basic Camera Operation