camera-explorer/CameraExplorer/DataContext.cs

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

2012-09-03 15:17:24 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
2012-09-03 15:17:24 +04:00
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
2012-09-03 15:17:24 +04:00
using Windows.Phone.Media.Capture;
namespace CameraExplorer
{
class DataContext : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
static DataContext _singleton;
public static CameraExplorer.DataContext Singleton
2012-09-03 15:17:24 +04:00
{
get
{
if (_singleton == null)
_singleton = new CameraExplorer.DataContext();
2012-09-03 15:17:24 +04:00
return _singleton;
}
2012-09-03 15:17:24 +04:00
}
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;
Settings.CreateParameters();
2012-09-03 15:17:24 +04:00
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Device"));
}
}
}
}
public MemoryStream ImageStream { get; set; }
2012-09-03 15:17:24 +04:00
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);
PhotoCaptureDevice d = await PhotoCaptureDevice.OpenAsync(sensorLocation, initialResolution);
await d.SetPreviewResolutionAsync(previewResolution);
await d.SetCaptureResolutionAsync(captureResolution);
d.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, d.SensorRotationInDegrees);
2012-09-03 15:17:24 +04:00
Device = d;
2012-09-03 15:17:24 +04:00
}
public void UnitializeCamera()
{
if (Device != null)
{
Device.Dispose();
Device = null;
}
}
}
}