Tag: bitmapsource

有没有一个好的方法来转换BitmapSource和位图?

据我可以告诉唯一的方法来从BitmapSource转换为位图是通过不安全的代码…像这样(来自Lesters WPF博客 ): myBitmapSource.CopyPixels(bits, stride, 0); unsafe { fixed (byte* pBits = bits) { IntPtr ptr = new IntPtr(pBits); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb,ptr); return bitmap; } } 做相反的事情: System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 在框架中有一个更简单的方法吗? 那它不在的原因是什么(如果不是的话)? 我会认为这是相当有用的。 我需要它的原因是因为我使用AForge在WPF应用程序中执行某些图像操作。 WPF想要显示BitmapSource / ImageSource,但是AForge在位图上工作。