2011-03-28 90 views
1

我在加入我刚刚创建,但它是没有存储在类似位置的图像问题“C:...”WPF添加动态位图图像

所以我在想,如果有办法将该图像添加到wpf,而不需要首先保存....

我想要的例子。

Bitmap bit; 
LoadBitmap(bit); 
image = bit; 

回答

4

我发现在塔米尔Khason的博客here的解决方案:

使用

public static BitmapSource ConvertBitmap(System.Drawing.Bitmap source) 
{ 
    return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
        source.GetHbitmap(), 
        IntPtr.Zero, 
        Int32Rect.Empty, 
        System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 
} 

你可以做

Bitmap bit; 
LoadBitmap(bit); 
image.Source = ConvertBitmap(bit); 
+0

真棒,我现在没有得到错误。时间工作,并做出动态的工作:P ...谢谢 – 2011-03-28 15:48:56