今天 在用aforgr.net做图像处理的时候报了以下错误:
Unsupported pixel format of the source or template image 源或模板图像不支持的像素格式
从国外论坛找了一下解决办法:
The class implements exhaustive template matching algorithm, which performs complete scan of source image, comparing each pixel with corresponding pixel of template.
The class processes only grayscale 8 bpp and color 24 bpp images.
So, those are the image formats you must use.
As requested, to convert to a specific pixel format, you can do this:
public static Bitmap ConvertToFormat(this Image image, PixelFormat format)
{
Bitmap copy = new Bitmap(image.Width, image.Height, format);
using (Graphics gr = Graphics.FromImage(copy))
{
gr.DrawImage(image, new Rectangle(0, 0, copy.Width, copy.Height));
}
return copy;
} 中文翻译如下:
类实现了一个完整的扫描图像的模板匹配算法,对每个像素进行比较,并与相应像素的模板进行比较。
类只能处理灰度和彩色图像24 8 BPP BPP。
所以,这些都是你必须使用的图像格式。
按照要求,转换到一个特定的像素格式,可以做到这一点:
公共静态位图converttoformat(这个图像,像素格式格式)
{
位图拷贝=新的位图(image.width,图像。高度,格式);
使用(图形GR =图形图像(复制)。)
{
gr.drawimage(图像,新的矩形(0,0,宽度,高度复制。复制。));
}
返回副本;
}
|