一、转为bmp格式
//黑白相机
public static Bitmap Tobmp(IImageData)
{
int m_width = (int)IImageData.GetWidth();
int m_height = (int)IImageData.GetHeight();
IntPtr pBufferMono = IImageData.GetBuffer();
Bitmap bmp = new Bitmap(m_width, m_height, m_width, System.Drawing.Imaging.PixelFormat.Format8bppIndexed,pBufferMono);
//添加调色板
ColorPalette palette;
palette = bmp.Palette;
int i = 0;
for (i = 0; i <= 255; i++)
palette.Entries[i] = System.Drawing.Color.FromArgb(i, i, i);
bmp.Palette = palette;
return bmp;
}
//彩色相机
public static Bitmap Tobmp(IImageData)
{
int m_width = (int)IImageData.GetWidth();
int m_height = (int)IImageData.GetHeight();
IntPtr pBufferColor = IImageData.ConvertToRGB24(GX_VALID_BIT_LIST.GX_BIT_0_7, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
Bitmap bmp = new Bitmap(m_width, m_height, m_width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, pBufferColor);
return bmp;
}
二、转为Halcon的HObject格式
//黑白相机
public static HObject ToHObject(IImageData)
{
int m_width = (int)IImageData.GetWidth();
int m_height = (int)IImageData.GetHeight();
HOperatorSet.GenImage1(out HObject ho_image, "byte", m_width, m_height, IImageData.GetBuffer());
return ho_image;
}
//彩色相机
public static HObject ToHObject(IImageData)
{
int m_width = (int)IImageData.GetWidth();
int m_height = (int)IImageData.GetHeight();
IntPtr pBufferColor = IImageData.ConvertToRGB24(GX_VALID_BIT_LIST.GX_BIT_0_7, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
HOperatorSet.GenImageInterleaved(out HObject ho_image, pBufferColor, "bgr", m_width, m_height, -1, "byte", m_width, m_height, 0, 0, -1, 0);
return ho_image;
}