4

ピクチャ ボックスに System.Windows.Media.Imaging.BitmapSource を描画したいと考えています。WPFアプリケーションでは、私はこれでそれを行います:

image1.Source =BitmapSource.Create(....................);

しかし今、私はフォームを持っています。フォームに PresentationCore.dll をインポートして、BitmapSource を取得します。しかし、今、このようなPictureBoxでどのように描画または表示できますか? :

pictureBox1.Image=BitmapSource.Create(.....................);

私を助けてください。ありがとう。

4

3 に答える 3

3

なぜwpf固有のものを使いたい/使う必要があるのですか?

このスニペットを見てください BitmapSource を Bitmap に変換する方法

Bitmap BitmapFromSource(BitmapSource bitmapsource)
{
    Bitmap bitmap;
    using (MemoryStream outStream = new MemoryStream())
    {
        BitmapEncoder enc = new BmpBitmapEncoder();
        enc.Frames.Add(BitmapFrame.Create(bitmapsource));
        enc.Save(outStream);
        bitmap = new Bitmap(outStream);
    }
    return bitmap;
}

使用法:

pictureBox1.Image = BitmapFromSource(yourBitmapSource);

画像ファイルを開く場合...:

pictureBox1.Image = System.Drawing.Image.FromFile("C:\\image.jpg");
于 2012-08-29T12:49:09.487 に答える
0

大丈夫ですか?

ImageSource imgSourceFromBitmap = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
于 2012-08-30T10:52:01.533 に答える