コード例 #1
0
        private frmLoadingImages OpenProgressForm()
        {
            frmLoadingImages frmLoading = null;
            Form             ownerForm  = null;

            ownerForm  = Application.OpenForms.Cast <Form>().FirstOrDefault(x => x != null && x.Owner == null);
            frmLoading = new frmLoadingImages();
            frmLoading.Show(ownerForm);
            frmLoading.Cursor = Cursors.WaitCursor;
            frmLoading.Invalidate();
            if (ownerForm != null)
            {
                try
                {
                    ownerForm.Parent = ownerForm;
                }
                catch
                { }
                ownerForm.Cursor = Cursors.WaitCursor;
                ownerForm.Update();
            }
            Application.DoEvents();

            return(frmLoading);
        }
コード例 #2
0
        private void CloseProgressForm(frmLoadingImages frmLoading)
        {
            if (frmLoading != null)
            {
                if (frmLoading.Owner != null)
                {
                    frmLoading.Owner.Cursor = Cursors.Default;
                    frmLoading.Owner.Update();
                }

                frmLoading.Close();
            }
        }
コード例 #3
0
        private frmLoadingImages OpenProgressForm(IWin32Window ownerForm)
        {
            frmLoadingImages frmLoading = null;

            frmLoading = new frmLoadingImages();
            frmLoading.Show(ownerForm);
            frmLoading.Cursor = Cursors.WaitCursor;
            frmLoading.Invalidate();

            if (frmLoading.Owner != null)
            {
                frmLoading.Owner.Cursor = Cursors.WaitCursor;
                frmLoading.Owner.Update();
            }

            Application.DoEvents();

            return(frmLoading);
        }
コード例 #4
0
        private void BufferEmbeddedOccultationVideo(IWin32Window ownerForm)
        {
            string occultationVideoFileName = Path.GetFullPath(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Resources\simulator.pix");

            width  = 320;
            height = 264;

            frmLoadingImages frmLoading = OpenProgressForm(ownerForm);

            try
            {
                using (var decompressedData = new MemoryStream())
                {
                    using (var sourceFile = new FileStream(occultationVideoFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                        using (var gzip = new GZipStream(sourceFile, CompressionMode.Decompress))
                        {
                            const int size = 4096;

                            byte[] bytes = new byte[size];
                            int    numBytes;
                            while ((numBytes = gzip.Read(bytes, 0, size)) > 0)
                            {
                                decompressedData.Write(bytes, 0, numBytes);
                            }

                            decompressedData.Flush();
                        }

                    decompressedData.Position = 0;

                    byte[] frameBuffer = new byte[width * height];

                    for (int i = 0; i < 200; i++)
                    {
                        int[,] frame = new int[height, width];
                        decompressedData.Read(frameBuffer, 0, frameBuffer.Length);

                        for (int j = 0; j < height; j++)
                        {
                            for (int k = 0; k < width; k++)
                            {
                                frame[j, k] = (int)frameBuffer[k + j * width];
                            }
                        }

                        allImagesPixels.Add(frame);
                        frmLoading.SetProgress(i, 200);
                    }
                }

                errorBitmap         = null;
                errorPixels         = null;
                bufferedImageWidth  = width;
                bufferedImageHeight = height;
            }
            catch (Exception ex)
            {
                DebugTrace.TraceError(ex);

                errorBitmap = new Bitmap(width, height);
                PrepareErrorMessage(ex.Message);
                errorPixels = CopyBitmapPixels(errorBitmap);
            }
            finally
            {
                CloseProgressForm(frmLoading);
            }
        }
コード例 #5
0
        private void BufferVideoFrames(IWin32Window ownerForm, string bitmapFilesLocation)
        {
            frmLoadingImages frmLoading = OpenProgressForm(ownerForm);

            try
            {
                string[] files = Directory.GetFiles(bitmapFilesLocation, "*.bmp");
                allFiles.AddRange(files);

                allFiles.Sort();

                if (allFiles.Count > 0)
                {
                    width  = 0;
                    height = 0;

                    // TODO: Use .NET 4 multithreaded loading

                    for (int i = 0; i < allFiles.Count; i++)
                    {
                        var bmp = new Bitmap(allFiles[i]);

                        if (width == 0 && height == 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;
                        }
                        else if (width != bmp.Width || height != bmp.Height)
                        {
                            throw new ApplicationException("All bitmaps must be the same size.");
                        }

                        int[,] pixels = CopyBitmapPixels(bmp);
                        allImagesPixels.Add(pixels);

                        frmLoading.SetProgress(i + 1, allFiles.Count);
                    }

                    errorBitmap         = null;
                    errorPixels         = null;
                    bufferedImageWidth  = width;
                    bufferedImageHeight = height;

                    DebugTrace.TraceInfo(string.Format("Loaded {0} camera images from '{1}'", allFiles.Count, bitmapFilesLocation));
                }
                else
                {
                    errorBitmap = new Bitmap(width, height);
                    PrepareErrorMessage(string.Format("No bmp file found in '{0}'", bitmapFilesLocation));
                    errorPixels = CopyBitmapPixels(errorBitmap);

                    DebugTrace.TraceError(string.Format("No camera images found in '{0}'", bitmapFilesLocation));
                }
            }
            catch (Exception ex)
            {
                DebugTrace.TraceError(ex);

                errorBitmap = new Bitmap(width, height);
                PrepareErrorMessage(ex.Message);
                errorPixels = CopyBitmapPixels(errorBitmap);
            }
            finally
            {
                CloseProgressForm(frmLoading);
            }
        }