优化System.Windows.Drawing.Bitmap和System.Windows.Media.Imaging.BitmapImage之间的转换
|
我正在一个项目中,该项目使用以下函数在System.Drawing.Bitmap图像之间进行转换,这些图像是使用System.Drawing.Printing API和System.Windows.Media.Imaging.BitmapImage类所必需的在WPF中显示图像:
public System.Windows.Media.Imaging.BitmapImage getDisplayImage(System.Drawing.Bitmap bm)
{
MemoryStream ms = new MemoryStream();
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
System.Windows.Media.Imaging.BitmapImage wpfImg = new System.Windows.Media.Imaging.BitmapImage();
ms.Seek(0, SeekOrigin.Begin);
wpfImg.BeginInit();
wpfImg.StreamSource = ms;
wpfImg.EndInit();
return wpfImg;
}
它当然可以完成任务,但是对于我用于它的数据(图像尺寸大约为5400 x 3600)来说,速度会很慢。是否有更有效的方法在这些格式之间进行转换?
没有找到相关结果
已邀请:
0 个回复