2012-10-19 15:11:52 +04:00
|
|
|
|
/*
|
2014-11-27 14:32:54 +03:00
|
|
|
|
* Copyright (c) 2012-2014 Microsoft Mobile. All rights reserved.
|
|
|
|
|
* See the license file delivered with this project for more information.
|
2012-10-19 15:11:52 +04:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2012-10-18 16:47:56 +04:00
|
|
|
|
using System.Collections.ObjectModel;
|
2012-09-03 15:17:24 +04:00
|
|
|
|
using System.ComponentModel;
|
2012-09-12 18:32:36 +04:00
|
|
|
|
using System.IO;
|
2013-06-20 16:21:42 +04:00
|
|
|
|
using System.IO.IsolatedStorage;
|
2012-09-03 15:17:24 +04:00
|
|
|
|
using Windows.Phone.Media.Capture;
|
|
|
|
|
|
|
|
|
|
namespace CameraExplorer
|
|
|
|
|
{
|
2012-10-23 16:29:35 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// CameraExplorer.DataContext holds all application widely used instances, like parameters,
|
|
|
|
|
/// camera instance and image memory stream.
|
|
|
|
|
/// </summary>
|
2012-09-03 15:17:24 +04:00
|
|
|
|
class DataContext : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
2012-10-18 16:47:56 +04:00
|
|
|
|
private static DataContext _singleton;
|
2013-06-20 16:21:42 +04:00
|
|
|
|
private static IsolatedStorageSettings _settings = IsolatedStorageSettings.ApplicationSettings;
|
2012-10-18 16:47:56 +04:00
|
|
|
|
private PhotoCaptureDevice _device = null;
|
|
|
|
|
private ObservableCollection<Parameter> _parameters = new ObservableCollection<Parameter>();
|
|
|
|
|
|
2012-10-23 16:29:35 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Singleton instance accessor.
|
|
|
|
|
/// </summary>
|
2012-10-18 16:47:56 +04:00
|
|
|
|
public static DataContext Singleton
|
2012-09-03 15:17:24 +04:00
|
|
|
|
{
|
2012-09-12 18:32:36 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_singleton == null)
|
2012-10-18 16:47:56 +04:00
|
|
|
|
{
|
|
|
|
|
_singleton = new 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
|
|
|
|
}
|
|
|
|
|
|
2012-10-23 16:29:35 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Collection of camera parameters.
|
|
|
|
|
/// </summary>
|
2012-10-18 16:47:56 +04:00
|
|
|
|
public ObservableCollection<Parameter> Parameters
|
2012-09-03 15:17:24 +04:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-10-18 16:47:56 +04:00
|
|
|
|
return _parameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
if (_parameters != value)
|
|
|
|
|
{
|
|
|
|
|
_parameters = value;
|
2012-09-03 15:17:24 +04:00
|
|
|
|
|
2012-10-18 16:47:56 +04:00
|
|
|
|
if (PropertyChanged != null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs("Parameters"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-03 15:17:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-23 16:29:35 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Camera instance. Setting new camera instance to this property causes the Parameters
|
|
|
|
|
/// property to be updated as well with the new parameters from the new camera.
|
|
|
|
|
/// </summary>
|
2012-09-03 15:17:24 +04:00
|
|
|
|
public PhotoCaptureDevice Device
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_device != value)
|
|
|
|
|
{
|
|
|
|
|
_device = value;
|
2012-10-18 16:47:56 +04:00
|
|
|
|
|
|
|
|
|
if (_device != null)
|
|
|
|
|
{
|
|
|
|
|
ObservableCollection<Parameter> newParameters = new ObservableCollection<Parameter>();
|
|
|
|
|
|
|
|
|
|
Action<Parameter> addParameter = (Parameter parameter) =>
|
|
|
|
|
{
|
|
|
|
|
if (parameter.Supported && parameter.Modifiable)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
parameter.Refresh();
|
2013-06-20 16:21:42 +04:00
|
|
|
|
parameter.SetSavedOrDefault();
|
2012-10-18 16:47:56 +04:00
|
|
|
|
|
|
|
|
|
newParameters.Add(parameter);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Debug.WriteLine("Setting default to " + parameter.Name.ToLower() + " failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Debug.WriteLine("Parameter " + parameter.Name.ToLower() + " is not supported or not modifiable");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addParameter(new SceneModeParameter(_device));
|
|
|
|
|
addParameter(new WhiteBalancePresetParameter(_device));
|
|
|
|
|
addParameter(new FlashModeParameter(_device));
|
|
|
|
|
addParameter(new FlashPowerParameter(_device));
|
|
|
|
|
addParameter(new IsoParameter(_device));
|
|
|
|
|
addParameter(new ExposureCompensationParameter(_device));
|
|
|
|
|
addParameter(new ExposureTimeParameter(_device));
|
|
|
|
|
addParameter(new AutoFocusRangeParameter(_device));
|
|
|
|
|
addParameter(new FocusIlluminationModeParameter(_device));
|
|
|
|
|
addParameter(new CaptureResolutionParameter(_device));
|
|
|
|
|
|
|
|
|
|
Parameters = newParameters;
|
|
|
|
|
}
|
2012-09-12 18:32:36 +04:00
|
|
|
|
|
2012-09-03 15:17:24 +04:00
|
|
|
|
if (PropertyChanged != null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs("Device"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 16:21:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Settings accessors.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IsolatedStorageSettings Settings
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _settings;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-23 16:29:35 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Memory stream to hold the image data captured in MainPage but consumed in PreviewPage.
|
|
|
|
|
/// </summary>
|
2012-09-13 10:55:53 +04:00
|
|
|
|
public MemoryStream ImageStream { get; set; }
|
2012-09-03 15:17:24 +04:00
|
|
|
|
}
|
2012-10-12 13:24:39 +04:00
|
|
|
|
}
|