2012-09-03 15:17:24 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2012-09-12 18:32:36 +04:00
|
|
|
|
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;
|
2012-09-12 18:32:36 +04:00
|
|
|
|
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;
|
2012-09-12 18:32:36 +04:00
|
|
|
|
public static CameraExplorer.DataContext Singleton
|
2012-09-03 15:17:24 +04:00
|
|
|
|
{
|
2012-09-12 18:32:36 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_singleton == null)
|
|
|
|
|
_singleton = new CameraExplorer.DataContext();
|
2012-09-03 15:17:24 +04:00
|
|
|
|
|
2012-09-12 18:32:36 +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;
|
|
|
|
|
|
2012-09-18 14:47:44 +04:00
|
|
|
|
Settings.CreateParameters();
|
2012-09-12 18:32:36 +04:00
|
|
|
|
|
2012-09-03 15:17:24 +04:00
|
|
|
|
if (PropertyChanged != null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs("Device"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-13 10:55:53 +04:00
|
|
|
|
public MemoryStream ImageStream { get; set; }
|
2012-09-12 18:32:36 +04:00
|
|
|
|
|
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);
|
|
|
|
|
|
2012-09-12 18:32:36 +04:00
|
|
|
|
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
|
|
|
|
|
2012-09-12 18:32:36 +04:00
|
|
|
|
Device = d;
|
2012-09-03 15:17:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnitializeCamera()
|
|
|
|
|
{
|
|
|
|
|
if (Device != null)
|
|
|
|
|
{
|
|
|
|
|
Device.Dispose();
|
|
|
|
|
Device = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|