private async void OnColorMapImageTapped(object sender, TappedRoutedEventArgs e)
        {
            RenderTargetBitmap bitmap = new RenderTargetBitmap();
            await bitmap.RenderAsync(colorMapImage);

            uint width  = (uint)bitmap.PixelWidth;
            uint height = (uint)bitmap.PixelHeight;

            Point point  = e.GetPosition(colorMapImage);
            int   pointX = (int)((double)(point.X / colorMapImage.ActualWidth) * width);
            int   pointY = (int)((double)(point.Y / colorMapImage.ActualHeight) * height);

            System.Diagnostics.Debug.WriteLine("Picked point is [" + (int)point.X + "; " + (int)point.Y
                                               + "], size of the color map image is "
                                               + (int)colorMapImage.ActualWidth + "x" + (int)colorMapImage.ActualHeight
                                               + " => point in image is [" + pointX + "; " + pointY + "]");

            IBuffer pixelBuffer = await bitmap.GetPixelsAsync();

            _brightnessSliderValueChangedByPickedColor = true;
            PreviewColor = ImageProcessingUtils.GetColorAtPoint(pixelBuffer, width, height, new Point()
            {
                X = pointX, Y = pointY
            });
            _originalColor = PreviewColor;
        }
Exemplo n.º 2
0
        private async void OnFrameCapturedAsync(byte[] pixelArray, int frameWidth, int frameHeight, int frameId)
        {
            _videoEngine.Messenger.FrameCaptured -= OnFrameCapturedAsync;
            System.Diagnostics.Debug.WriteLine("OnFrameCapturedAsync");

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                WriteableBitmap bitmap = await ImageProcessingUtils.PixelArrayToWriteableBitmapAsync(pixelArray, frameWidth, frameHeight);

                if (bitmap != null)
                {
                    capturedPhotoImage.Source = bitmap;
                    bitmap.Invalidate();
                    capturedPhotoImage.Visibility = Visibility.Visible;

                    if (frameId == ColorPickFrameRequestId)
                    {
                        int scaledWidth = (int)(_videoEngine.ResolutionWidth *viewfinderCanvas.ActualHeight / _videoEngine.ResolutionHeight);
                        int pointX      = (int)(((_viewFinderCanvasTappedPoint.X - (viewfinderCanvas.ActualWidth - scaledWidth) / 2) / scaledWidth) * frameWidth);
                        int pointY      = (int)((_viewFinderCanvasTappedPoint.Y / viewfinderCanvas.ActualHeight) * frameHeight);

                        SetColor(ImageProcessingUtils.GetColorAtPoint(
                                     bitmap, (uint)frameWidth, (uint)frameHeight, new Point()
                        {
                            X = pointX, Y = pointY
                        }));
                    }

                    if (_hideCapturePhotoImageTimer != null)
                    {
                        _hideCapturePhotoImageTimer.Dispose();
                        _hideCapturePhotoImageTimer = null;
                    }

                    _hideCapturePhotoImageTimer = new Timer(HideCapturedPhotoImageAsync, null, 8000, Timeout.Infinite);
                }

                _videoEngine.Messenger.FrameCaptured += OnFrameCapturedAsync;
            });
        }