您的位置:首页 > 其它

将winform得到的bitmap格式的普片转化成wpf image格式的图片

2011-06-15 16:17 363 查看
BitmapSource GetBitmapSource(Bitmap _bitmap)
{
Rectangle destRect = new Rectangle(0, 0, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight);

var bitmap = new Bitmap((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(_bitmap, destRect, destRect, GraphicsUnit.Pixel);
}
return Tobitmap(_bitmap);

}

BitmapSource Tobitmap(Bitmap bmp)
{
BitmapSource returnSource;

try
{
returnSource = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
catch
{
returnSource = null;
}

return returnSource;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: