System.Windows.Media.Imaging.BitmapSource转System.Drawing.Image我把这两个库绑在了一起。一个只提供System.Windows.Media.Imaging.BitmapSource类型的输出,另一个只接受System.Drawing.Image类型的输入。如何进行转换?privateSystem.Drawing.BitmapBitmapFromSource(BitmapSourcebitmapsource){System.Drawing.Bitmap位图;使用(MemoryStreamoutStream=newMemoryStream()){BitmapEncoderenc=newBmpBitmapEncoder();enc.Frames.Add(BitmapFrame.Create(bitmapsource));enc.Save(outStream);bitmap=newSystem.Drawing.Bitmap(outStream);}返回位图;这是另一种做同样事情的技术。接受的答案有效,但我对具有alpha通道的图像有疑问(即使在切换到PngBitmapEncoder之后)。这种技术也可能更快,因为它只是在转换为兼容的像素格式后制作像素的原始副本。以上就是C#学习教程:ConvertingSystem.Windows.Media.Imaging.BitmapSourcetoSystem.Drawing.Image的全部内容分享。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注——publicBitmapBitmapFromSource(System.Windows.Media.Imaging.BitmapSourcebitmapsource){//转换图片格式varsrc=newSystem.Windows.Media.Imaging.FormatConvertedBitmap();src.开始初始化();src.Source=位图源;来源vardata=bitmap.LockBits(newRectangle(Point.Empty,bitmap.Size),System.Drawing.Imaging.ImageLockMode.WriteOnly,System.Drawing.Imaging.PixelFormat.Format32bppArgb);src.CopyPixels(System.Windows.Int32Rect.Empty,data.Scan0,??data.Height*data.Stride,data.Stride);位图.UnlockBits(数据);返回位图;}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除除非转载,否则请注明出处:
