Exemple #1
0
 void _liveviewtimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (_oper_in_progress)
     {
         return;
     }
     _oper_in_progress = true;
     try
     {
         if (!Freeze)
         {
             LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
         }
         Dispatcher.Invoke(new Action(DisplayLiveView));
     }
     catch (Exception exception)
     {
         Log.Debug("Error get live view data *Astro ", exception);
     }
     _oper_in_progress = false;
 }
Exemple #2
0
        private void GetLiveImage()
        {
            if (oper_in_progress)
            {
                return;
            }
            oper_in_progress = true;
            _totalframes++;
            try
            {
                LiveViewData = LiveViewManager.GetLiveViewImage(SelectedPortableDevice);
            }
            catch (Exception)
            {
                _retries++;
                oper_in_progress = false;
                return;
            }

            if (LiveViewData == null || LiveViewData.ImageData == null)
            {
                _retries++;
                oper_in_progress = false;
                return;
            }

            Dispatcher.Invoke(new Action(delegate
            {
                try
                {
                    WriteableBitmap preview;
                    if (LiveViewData != null && LiveViewData.ImageData != null)
                    {
                        MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                               LiveViewData.ImagePosition,
                                                               LiveViewData.ImageData.Length -
                                                               LiveViewData.ImagePosition);

                        using (var bmp = new Bitmap(stream))
                        {
                            preview =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(bmp));

                            Bitmap newbmp = bmp;

                            WriteableBitmap writeableBitmap;

                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(newbmp));

                            //DrawGrid(writeableBitmap);
                            writeableBitmap.Freeze();
                            image1.BeginInit();
                            image1.Source = writeableBitmap;
                            image1.EndInit();
                        }
                        stream.Close();
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    _retries++;
                    oper_in_progress = false;
                }
            }));
            _retries         = 0;
            oper_in_progress = false;
        }