public void Get()
        {
            try
            {
                var LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
                if (LiveViewData != null && LiveViewData.ImageData != null)
                {
                    MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                           LiveViewData.
                                                           ImageDataPosition,
                                                           LiveViewData.ImageData.
                                                           Length -
                                                           LiveViewData.
                                                           ImageDataPosition);

                    using (var res = new Bitmap(stream))
                    {
                        var writeableBitmap =
                            BitmapFactory.ConvertToPbgra32Format(
                                BitmapSourceConvert.ToBitmapSource(res));
                        writeableBitmap.Freeze();
                        Bitmap           = writeableBitmap;
                        IsMovieRecording = LiveViewData.MovieIsRecording;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 2
0
        public override void GetLiveImage()
        {
            lock (_locker)
            {
                try
                {
                    LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
                }
                catch (Exception)
                {
                    return;
                }

                if (LiveViewData == null || LiveViewData.ImageData == null)
                {
                    return;
                }
                MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                       LiveViewData.ImageDataPosition,
                                                       LiveViewData.ImageData.Length -
                                                       LiveViewData.ImageDataPosition);
                using (var bmp = new Bitmap(stream))
                {
                    Bitmap res     = bmp;
                    var    preview = BitmapFactory.ConvertToPbgra32Format(BitmapSourceConvert.ToBitmapSource(res));
                    var    zoow    = preview.Crop((int)(CentralPoint.X - (StarWindowSize / 2)),
                                                  (int)(CentralPoint.Y - (StarWindowSize / 2)),
                                                  StarWindowSize, StarWindowSize);
                    CalculateStarSize(zoow);
                    zoow.Freeze();
                    StarWindow = zoow;
                    if (CameraDevice.LiveViewImageZoomRatio.Value == "All")
                    {
                        preview.Freeze();
                        Preview = preview;
                    }


                    if (Brightness != 0)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                        res = filter.Apply(res);
                    }
                    if (EdgeDetection)
                    {
                        var filter = new FiltersSequence(
                            Grayscale.CommonAlgorithms.BT709,
                            new HomogenityEdgeDetector()
                            );
                        res = filter.Apply(res);
                    }

                    var _bitmap = BitmapFactory.ConvertToPbgra32Format(BitmapSourceConvert.ToBitmapSource(res));
                    DrawGrid(_bitmap);

                    if (ZoomFactor > 1)
                    {
                        double d = _bitmap.PixelWidth / (double)ZoomFactor;
                        double h = _bitmap.PixelHeight / (double)ZoomFactor;
                        _bitmap = _bitmap.Crop((int)(CentralPoint.X - (d / 2)), (int)(CentralPoint.Y - (h / 2)),
                                               (int)d, (int)h);
                    }

                    _bitmap.Freeze();
                    Bitmap = _bitmap;
                }
            }
        }