示例#1
0
        public static void GetIntegratedFrame(int startFrameNo, int framesToIntegrate, bool isSlidingIntegration, bool isMedianAveraging, out uint[] pixels, out uint[] originalPixels, out Bitmap bitmap, out byte[] bitmapBytes)
        {
            if (s_fileInfo != null)
            {
                originalPixels = new uint[s_fileInfo.Width * s_fileInfo.Height];
                pixels         = new uint[s_fileInfo.Width * s_fileInfo.Height];
                byte[] bitmapPixels = new byte[s_fileInfo.Width * s_fileInfo.Height * 3 + 40 + 14 + 1];
                bitmapBytes = new byte[s_fileInfo.Width * s_fileInfo.Height];

                TangraVideoGetIntegratedFrame(startFrameNo, framesToIntegrate, isSlidingIntegration, isMedianAveraging, pixels, bitmapPixels, bitmapBytes);

                byte[] rawBitmapBytes = new byte[(s_fileInfo.Width * s_fileInfo.Height * 3) + 40 + 14 + 1];

                Array.Copy(pixels, originalPixels, pixels.Length);

                TangraCore.PreProcessors.ApplyPreProcessingPixelsOnly(originalPixels, pixels, s_fileInfo.Width, s_fileInfo.Height, 8, 0 /* No normal value for FITS files */, 0 /* No exposure support for 8 bit darks. They must be same exposure */);

                TangraCore.GetBitmapPixels(s_fileInfo.Width, s_fileInfo.Height, pixels, rawBitmapBytes, bitmapBytes, true, 8, 0);

                bitmap = Pixelmap.ConstructBitmapFromBitmapPixels(bitmapBytes, s_fileInfo.Width, s_fileInfo.Height);
            }
            else
            {
                bitmap = new Bitmap(100, 100);
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.Clear(Color.White);
                    g.DrawString("Invalid file.", s_ErrorFont, Brushes.Red, 10, 10);
                    g.Save();
                }

                bitmapBytes    = new byte[100 * 100];
                pixels         = new uint[100 * 100];
                originalPixels = new uint[100 * 100];
            }
        }
示例#2
0
        public static void GetFrame(int frameNo, out uint[] pixels, out uint[] originalPixels, out Bitmap videoFrame, out byte[] bitmapBytes)
        {
            originalPixels = null;

            if (s_fileInfo != null)
            {
                int width  = s_fileInfo.Width;
                int height = s_fileInfo.Height;
                pixels         = new uint[width * height];
                originalPixels = new uint[width * height];
                byte[] bitmapPixels = new byte[width * height * 3 + 40 + 14 + 1];
                bitmapBytes = new byte[width * height];
                int rv = -1;
                try
                {
                    lock (s_SyncRoot)
                    {
                        rv = TangraVideoGetFrame(frameNo, pixels, bitmapPixels, bitmapBytes);

                        if (rv == 0)
                        {
                            byte[] rawBitmapBytes = new byte[(width * height * 3) + 40 + 14 + 1];

                            Array.Copy(pixels, originalPixels, pixels.Length);

                            TangraCore.PreProcessors.ApplyPreProcessingPixelsOnly(originalPixels, pixels, width, height, 8, 0 /* No normal value for FITS files */, 0 /* No exposure support for 8 bit darks. They must be same exposure */);

                            TangraCore.GetBitmapPixels(width, height, pixels, rawBitmapBytes, bitmapBytes, true, 8, 0);

                            videoFrame = Pixelmap.ConstructBitmapFromBitmapPixels(bitmapBytes, width, height);
                        }
                        else
                        {
                            throw new InvalidOperationException("The core returned an error when trying to get a frame. Error code: " + rv.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (rv == 0)
                    {
                        try
                        {
                            videoFrame = Pixelmap.ConstructBitmapFromBitmapPixels(bitmapBytes, width, height);
                            return;
                        }
                        catch (Exception ex2)
                        {
                            Trace.WriteLine(ex2.GetFullStackTrace());
                        }
                    }

                    videoFrame = new Bitmap(width, height);
                    using (Graphics g = Graphics.FromImage(videoFrame))
                    {
                        g.Clear(Color.White);
                        g.DrawString(ex.Message, s_ErrorFont, Brushes.Red, 10, 10);
                        g.Save();
                    }
                }
            }
            else
            {
                videoFrame = new Bitmap(100, 100);
                using (Graphics g = Graphics.FromImage(videoFrame))
                {
                    g.Clear(Color.White);
                    g.DrawString("Invalid file.", s_ErrorFont, Brushes.Red, 10, 10);
                    g.Save();
                }
                bitmapBytes = new byte[100 * 100];
                pixels      = new uint[100 * 100];
            }
        }