位图到图像转换

时间:2010-12-26 17:31:12

标签: c#

上一篇文章的更多信息(更具体)

喜 我想从emgucv和agorge.net同时获益。

我面临的问题是类型转换

//EMGUCV

Image<Bgr, Byte> image1 = new Image<Bgr, Byte>("file.jpg"); //read the image

// AFORGE.net
 system.drawing.Bitmap image2 = (Bitmap)Bitmap.FromFile("file.jpg");

我如何交换这两种类型。

位图 - &gt;图像(到基类)

如,

Bitmap grayImage = filter.Apply(image1.Bitmap);

now want to use
ImageViewer.Show(grayImage, "test"); //error

的问候, 沙赫扎德

2 个答案:

答案 0 :(得分:0)

实际上,System.Image.Bitmap类一个Image类。有关详细信息,请参阅documentationSystem.Drawing.Image is an abstract base class

就使用AForge而言,您可以使用grayscale class转换为灰度:

// create grayscale filter (BT709)
Grayscale filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
// apply the filter
Bitmap grayImage = filter.Apply( image );

AForge的Grayscale类在Apply调用中获取一个Bitmap实例,因此您只需使用Bitmap.FromFile方法。

编辑:有关使用AForge转换为灰度的更多信息

答案 1 :(得分:0)

Emgu CV的Image类有一个ToBitmap()方法。

所以它像以下一样微不足道:

image1.ToBitmap();