/// <summary> /// Starts up and selects a device's camera, and finds appropriate picture settings /// based on the provided resolution! /// </summary> /// <param name="preferGPUTexture">Do you prefer GPU textures, or do you prefer a NativeArray of colors? Certain optimizations may be present to take advantage of this preference.</param> /// <param name="resolution">Preferred resolution for taking pictures, note that resolutions are not guaranteed! Refer to CameraResolution for details.</param> /// <param name="onInitialized">When the camera is initialized, this callback is called! Some cameras may return immediately, others may take a while. Can be null.</param> public void Initialize(bool aPreferGPUTexture, CameraResolution aResolution, Action aOnInitialized) { resolution = aResolution; Resolution cameraResolution = resolution.nativeResolution == NativeResolutionMode.Smallest ? PhotoCapture.SupportedResolutions.OrderBy((res) => res.width * res.height).First() : PhotoCapture.SupportedResolutions.OrderBy((res) => - res.width * res.height).First(); cacheTex = new Texture2D(cameraResolution.width, cameraResolution.height); // Create a PhotoCapture object PhotoCapture.CreateAsync(false, delegate(PhotoCapture captureObject) { camera = captureObject; cameraParams = new CameraParameters(); cameraParams.hologramOpacity = 0.0f; cameraParams.cameraResolutionWidth = cameraResolution.width; cameraParams.cameraResolutionHeight = cameraResolution.height; cameraParams.pixelFormat = CapturePixelFormat.BGRA32; IntPtr unknown = camera.GetUnsafePointerToVideoDeviceController(); using (VideoDeviceControllerWrapperUWP wrapper = new VideoDeviceControllerWrapperUWP(unknown)) { wrapper.SetExposure(-7); wrapper.SetWhiteBalance(5000); wrapper.SetISO(80); } if (aOnInitialized != null) { aOnInitialized(); } isReady = true; }); }
/// <summary> /// Internal version of initialize. Should not be called more than once unless Shutdown has been called. /// </summary> /// <param name="preferGPUTexture"> /// Whether GPU textures are preferred over NativeArray of colors. Certain optimizations may be present to take advantage of this preference. /// </param> /// <param name="preferredResolution"> /// Preferred resolution for taking pictures. Note that resolutions are not guaranteed! Refer to CameraResolution for details. /// </param> /// <returns> /// A <see cref="Task"/> that represents the operation. /// </returns> private async Task InnerInitializeAsync(bool preferGPUTexture, CameraResolution preferredResolution) { // Store preferred resolution resolution = preferredResolution; // Find the nearest supported camera resolution to the preferred one Resolution cameraResolution = resolution.nativeResolution == NativeResolutionMode.Smallest ? PhotoCapture.SupportedResolutions.OrderBy((res) => res.width * res.height).First() : PhotoCapture.SupportedResolutions.OrderBy((res) => - res.width * res.height).First(); // Create the texture cache cacheTex = new Texture2D(cameraResolution.width, cameraResolution.height); // Setup parameters for the camera cameraParams = new CameraParameters(); cameraParams.hologramOpacity = 0.0f; cameraParams.cameraResolutionWidth = cameraResolution.width; cameraParams.cameraResolutionHeight = cameraResolution.height; cameraParams.pixelFormat = CapturePixelFormat.BGRA32; // Create the PhotoCapture camera camera = await CameraExtensions.CreateAsync(false); // Create the wrapper IntPtr unknown = camera.GetUnsafePointerToVideoDeviceController(); wrapper = new VideoDeviceControllerWrapperUWP(unknown); }