Exemple #1
0
        /// <summary>
        /// Creates a Snapshot from a windowless control
        /// </summary>
        /// <param name="control">control that is being drawn to by the VMR9</param>
        public Snapshot(IVMRWindowlessControl9 control)
        {
            int hr;

            hr = control.GetCurrentImage(out _dib);
            DsError.ThrowExceptionForHR(hr);
        }
        public void VideoWindowSnapshot(IVMRFilterConfig9 renderer)
        {
            if (null == VmrRenderer)
            {
                return;
            }

            IVMRWindowlessControl9 ctrl = (IVMRWindowlessControl9)renderer;
            IntPtr imgptr = IntPtr.Zero;
            Bitmap bmp    = null;

            try
            {
                ctrl.GetCurrentImage(out imgptr);
                if (IntPtr.Zero != imgptr)
                {
                    BitmapInfoHeader header = new BitmapInfoHeader();
                    Marshal.PtrToStructure(imgptr, header);
                    //stride formula comes from MSDN
                    //https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
                    var stride = ((((header.Width * header.BitCount) + 31) & ~31) >> 3);

                    //暫時假定輸出圖像是純DIB沒有Color Mask等額外資訊
                    bmp = new Bitmap(header.Width, header.Height, stride,
                                     PixelFormat.Format32bppArgb, imgptr + header.Size);
                    //注意這邊撈出的CurrentImage,是上下顛倒狀態(沿著X軸鏡射)
                    //要把它再鏡射回來才能存檔
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                    SaveFileDialog dlg = new SaveFileDialog();
                    dlg.Filter           = "Bitmap File (*.bmp)|*.bmp";
                    dlg.InitialDirectory = BinPath;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        bmp.Save(dlg.FileName, ImageFormat.Jpeg);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save snapshot bmp file : " + ex.Message);
            }
            finally
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                }
                if (IntPtr.Zero != imgptr)
                {
                    Marshal.FreeCoTaskMem(imgptr);
                }
            }
        }
Exemple #3
0
        public override bool GetCurrentImage(out BITMAPINFOHEADER header, out IntPtr dibFull, out IntPtr dibDataOnly)
        {
            int hr = _pVMRWindowlessControl9.GetCurrentImage(out dibFull);

            if (DsHlp.SUCCEEDED(hr))
            {
                header      = (BITMAPINFOHEADER)Marshal.PtrToStructure(dibFull, typeof(BITMAPINFOHEADER));
                dibDataOnly = new IntPtr(dibFull.ToInt64() + Marshal.SizeOf(typeof(BITMAPINFOHEADER)));
                return(true);
            }
            else
            {
                header      = new BITMAPINFOHEADER();
                dibDataOnly = IntPtr.Zero;
                return(false);
            }
        }
Exemple #4
0
        private void snapImage()
        {
            if (windowlessCtrl != null)
            {
                IntPtr currentImage = IntPtr.Zero;
                Bitmap bmp          = null;

                try
                {
                    int hr = windowlessCtrl.GetCurrentImage(out currentImage);
                    DsError.ThrowExceptionForHR(hr);

                    if (currentImage != IntPtr.Zero)
                    {
                        BitmapInfoHeader structure = new BitmapInfoHeader();
                        Marshal.PtrToStructure(currentImage, structure);

                        bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, new IntPtr(currentImage.ToInt64() + 40));
                        bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            bmp.Save(saveFileDialog.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                }
                catch (Exception anyException)
                {
                    MessageBox.Show("Failed getting image: " + anyException.Message);
                }
                finally
                {
                    if (bmp != null)
                    {
                        bmp.Dispose();
                    }

                    Marshal.FreeCoTaskMem(currentImage);
                }
            }
        }