2

Image コントロールのコンテンツとして Bitmapsource オブジェクトを使用できますが、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 が再び使用されなくなった後、すぐにメモリを解放するサンプル メソッドはありますか。

4

2 に答える 2

1

Bitmapいいえ、直接使用することはできません。これは、System.Drawing.Bitmapが GDI+ ビットマップであるのに対し、BitmapImageinのようなクラスSystem.Windows.Media.Imagingは D3D/DirectX であるためです。

メモリ使用量に関しては、直接解放することはできませんが、通常はバックグラウンドで行われる何らかのキャッシュがあります。BitmapImageをロードしてキャッシュを無視する方法があります。

于 2008-10-09T19:31:13.873 に答える
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

All of these classes inherit from BitMapSource, so any of them could be used in that context.

于 2008-10-09T03:08:02.923 に答える