private void colorConversionBackgroundWorker() { // Grouping the property change notifications in a batch. List <PropertyChangedEventArgs> changeCache = new List <PropertyChangedEventArgs>(); changeCache.Add(new PropertyChangedEventArgs("CbText")); changeCache.Add(new PropertyChangedEventArgs("CrText")); changeCache.Add(new PropertyChangedEventArgs("CrOffset")); changeCache.Add(new PropertyChangedEventArgs("CbOffset")); changeCache.Add(new PropertyChangedEventArgs("YOffset")); changeCache.Add(new PropertyChangedEventArgs("ArgbText")); changeCache.Add(new PropertyChangedEventArgs("ArgbBrush")); // Obtain the YCbCr layout settings used by the camera buffer. var bufferLayout = cam.YCbCrPixelLayout; // Allocate the appropriately sized preview buffer. byte[] currentPreviewBuffer = new byte[bufferLayout.RequiredBufferSize]; // Continue processing until asked to stop in OnNavigatingFrom. while (!bgPleaseExit) { // Get the current preview buffer from the camera. cam.GetPreviewBufferYCbCr(currentPreviewBuffer); // The output parameters used in the following method. byte y; int cr; int cb; // Extract details about the pixel where the camera crosshairs meet. // This location is estimated to be X=320, Y=240. Adjust as desired. GetYCbCrFromPixel(bufferLayout, currentPreviewBuffer, 320, 240, out y, out cr, out cb); // Set page-level properties to the new YCbCr values. Y = y; Cb = cb; Cr = cr; Dispatcher.BeginInvoke(delegate() { // not threadsafe, but unlikely to be a problem in this case // Consolidating change notifications if (PropertyChanged != null) { foreach (var change in changeCache) { PropertyChanged(this, change); } } }); } }
/// <summary> /// Copies the current viewfinder frame into a buffer for further manipulation. /// </summary> /// <param name="pixelData">The pixel data.</param> /// <remarks> /// This method is already protected and only called when the service is currently running. /// </remarks> protected override void GetPreviewBufferYCbCrFromCamera(byte[] pixelData) { _photoCamera.GetPreviewBufferYCbCr(pixelData); }
/// <summary> /// Copies the current viewfinder frame into a buffer for further manipulation. /// </summary> /// <param name="pixelData">The pixel data.</param> public void GetPreviewBufferYCbCr(byte[] pixelData) { _photoCamera.GetPreviewBufferYCbCr(pixelData); }