camera-explorer/CameraExplorer/DataContext.cs

82 строки
2.2 KiB
C#
Исходник Обычный вид История

2012-09-03 15:17:24 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Phone.Media.Capture;
namespace CameraExplorer
{
class DataContext : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
static DataContext _singleton;
public static CameraExplorer.DataContext Singleton()
{
if (_singleton == null)
_singleton = new CameraExplorer.DataContext();
return _singleton;
}
Settings _settings = null;
public Settings Settings
{
get
{
if (_settings == null)
_settings = new Settings();
return _settings;
}
}
PhotoCaptureDevice _device = null;
public PhotoCaptureDevice Device
{
get
{
return _device;
}
set
{
if (_device != value)
{
_device = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Device"));
}
}
}
}
public async Task InitializeCamera(CameraSensorLocation sensorLocation)
{
Windows.Foundation.Size initialResolution = new Windows.Foundation.Size(640, 480);
Windows.Foundation.Size previewResolution = new Windows.Foundation.Size(640, 480);
Windows.Foundation.Size captureResolution = new Windows.Foundation.Size(640, 480);
Device = await PhotoCaptureDevice.OpenAsync(sensorLocation, initialResolution);
await Device.SetPreviewResolutionAsync(previewResolution);
await Device.SetCaptureResolutionAsync(captureResolution);
}
public void UnitializeCamera()
{
if (Device != null)
{
Device.Dispose();
Device = null;
}
}
}
}