【问题标题】:How to convert Bitmap to Image如何将位图转换为图像
【发布时间】:2012-03-11 03:46:37
【问题描述】:

我正在制作中值滤波器,问题是只有在Bitmap 中才能操作像素。稍后我想在使用ImagePictureBox 中显示结果。我想不出解决这个问题的方法……我唯一能想到的就是使用Stream,但不知道怎么做。求帮助~

private void toolStripPerformMedian_Click(object sender, EventArgs e)
{
    var filtered = Filters.MedianFilter(new Bitmap(_activeImageFile), 3);
    var n = Image.FromStream() //How to do this?
}

【问题讨论】:

  • 位图图像;您可以将 Bitmap 分配给 PictureBox 的 Image 属性。
  • @DJKRAZE,你提到的问题完全不相关...... OP使用的是GDI,而不是WPF
  • 此链接将帮助抱歉 Thomas.. wischik.com/lu/programmer/1bpp.html

标签: c# winforms gdi+


【解决方案1】:

这对我有用:

var codeBitmap = new Bitmap(your_info);
Image image = (Image)codeBitmap;

【讨论】:

  • 如果没有从哪个命名空间的上下文中提取这个 Image 类,这有点令人困惑。正如其他人所说,Bitmap 继承自 Image,因此除 image 之外的任何属性或参数都可以采用位图,不需要这种转换。如果它是 WIndows.Control.Image 然后这将不起作用,上面的代码也不会
  • @Dave 我看到了很多答案(关于将位图转换为图像)并尝试了许多代码 sn-ps 但除了我的答案中的那个之外,它们都没有工作。
【解决方案2】:

检查命名空间。 System.Drawing.Image 与位图兼容,System.Window.Control.Image - 不!

【讨论】:

    【解决方案3】:

    BitmapImage。它继承自 Image 类。

    From MSDN:

    [SerializableAttribute]
    [ComVisibleAttribute(true)]
    public sealed class Bitmap : Image
    

    【讨论】:

    • 不要与 BitmapImage 混淆。
    猜你喜欢
    • 2014-01-26
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多