BitmapSource是唯一可以在Image Source中使用的类型吗?

时间:2008-10-09 02:42:06

标签: wpf bitmap bitmapsource

我们可以使用Bitmapsource对象作为Image控件的内容,但是如果我只有Bitmap对象,我是否可以直接使用它,如果我使用以下方法将Bitmap转换为Bitmapsouce:

        Bitmap bitmap = imageObjToBeConvert;
        IntPtr HBitmap = bitmap.GetHbitmap();
        result = Imaging.CreateBitmapSourceFromHBitmap
            (HBitmap,
            IntPtr.Zero,
            Int32Rect.Empty,
            BitmapSizeOptions.FromEmptyOptions());
        DeleteObject(HBitmap);
        bitmap.Dispose();

需要一些时间。有没有办法直接使用Bitmap?

我发现BitmapSource似乎无法直接发布,是否有一个示例方法可以在不再使用Bitmapsouce之后立即释放内存。

2 个答案:

答案 0 :(得分:1)

  • System.Windows.Media.Imaging .. ::。BitmapFrame
  • System.Windows.Media.Imaging .. ::。BitmapImage的
  • System.Windows.Media.Imaging .. ::。CachedBitmap
  • System.Windows.Media.Imaging .. ::。ColorConvertedBitmap
  • System.Windows.Media.Imaging .. ::。CroppedBitmap
  • System.Windows.Media.Imaging .. ::。FormatConvertedBitmap
  • System.Windows.Media.Imaging .. ::。RenderTargetBitmap
  • System.Windows.Media.Imaging .. ::。TransformedBitmap
  • System.Windows.Media.Imaging .. ::。WriteableBitmap的

所有这些类都继承自BitMapSource,因此可以在该上下文中使用它们。

答案 1 :(得分:1)

不,您不能直接使用Bitmap。这是因为System.Drawing.Bitmap是GDI +位图,而BitmapImage中的System.Windows.Media.Imaging类是D3D / DirectX。

关于内存使用情况,您不能直接释放它,但通常会在后台进行某种缓存。有一些方法可以加载BitmapImage,以便忽略缓存。

相关问题