示例#1
0
        /// <summary>
        /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.ImageSource
        /// </summary>
        /// <param name="image">The Emgu CV Image</param>
        /// <returns>The equivalent BitmapSource</returns>
        public BitmapSource ToBitmapSource(IImage image)
        {
            ImageScale = 1000.0 / image.Bitmap.Width;

            var size = new Size((int)Math.Ceiling(image.Bitmap.Width * ImageScale),
                                (int)Math.Ceiling(image.Bitmap.Height * ImageScale));

            Image <Bgr, Byte> dst = new Image <Bgr, byte>(size);

            CvInvoke.Resize(image, dst, size, ImageScale, ImageScale, Inter.Linear);

            using (System.Drawing.Bitmap source = dst.Bitmap)
            {
                IntPtr ptr = source.GetHbitmap(); //obtain the Hbitmap

                BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    ptr,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()
                    );

                bs.Freeze();

                DeleteObject(ptr); //release the HBitmap
                return(bs);
            }
        }
示例#2
0
 public static void ShowInNamedWindow(Emgu.CV.IImage result, string debugWindowName)
 {
     if (!(debugWindowName.Equals("") || debugWindowName == null))
     {
         CvInvoke.cvNamedWindow(debugWindowName);
         CvInvoke.cvShowImage(debugWindowName, result.Ptr);
     }
 }
示例#3
0
        private void 保存截图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Emgu.CV.IImage frame      = imageBox1.Image;
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter = "BMP文件|*.bmp|JPG文件|*.jpg|JPEG文件|*.jpeg|所有文件|*.*";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show(saveDialog.FileName);
                frame.Save(saveDialog.FileName);
            }
        }