在 WPF 中使用位图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1738919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:12:20  来源:igfitidea点击:

Working with bitmap in WPF

wpfbitmappixel

提问by svick

Is there any sane way to work with bitmaps in WPF? I'd like similar functionality as System.Drawing.Bitmap: be able to load image from file and get and set the color of particular pixels.

有没有什么理智的方法可以在 WPF 中处理位图?我想要类似的功能System.Drawing.Bitmap:能够从文件加载图像并获取和设置特定像素的颜色。

I know about WriteableBitmap, but I don't want to work with Arrays of gods-know-what (I couldn't find that on MSDN), or pointers. I just want to read or write pixel, it shouldn't be that hard!

我知道WriteableBitmap,但我不想与Array诸神知道什么(我在MSDN上找不到)或指针一起工作。我只是想读或写像素,应该没那么难!

I also know that I can use Interopto work with System.Drawing.Bitmapin WPF, but that's not nice either.

我也知道,我可以使用互操作工作与System.Drawing.BitmapWPF中,但是这不是很好无论是。

回答by IV.

Here's something on how to do get pixel info from a System.Windows.Media.Imaging.BitmapImage.

这里有一些关于如何从System.Windows.Media.Imaging.BitmapImage.

Although, if you'd prefer to work with a System.Drawing.Bitmapyou might want to add a reference to System.Drawing.dlland use it instead.

虽然,如果您更喜欢使用 a ,System.Drawing.Bitmap您可能需要添加System.Drawing.dll对它的引用并使用它。

Here's a somewhat-related forum post on image manipulation in WPF.

这是有关 WPF 中图像处理一些相关论坛帖子

回答by Sean Vikoren

Add the assembly System.Drawing to your project.

将程序集 System.Drawing 添加到您的项目中。

References->Assemblies->Framework->System.Drawing