最近做项目有用到Halcon图像转成Bitmap格式的情况,在网上搜索部分代码整理调试了一下,效果不错,在博客中记录一下。
1、灰度图转Bitmap
//灰度图HObject转Bitmap
[DllImport("kernel32.dll")]
public static extern void CopyMemory(int Destination, int add, int Length);
private Bitmap HObjectToBitmap(HObject ho_Image)
{
try
{
HOperatorSet.GetImagePointer1(ho_Image, out HTuple pointer, out HTuple type, out HTuple width, out HTuple height);
Bitmap bmpImage = new Bitmap(width.I, height.I, PixelFormat.Format8bppIndexed);
ColorPalette pal = bmpImage.Palette;
for (int i = 0; i < 256; i++)
{
pal.Entries[i] = Color.FromArgb(255, i, i, i);
}
bmpImage.Palette = pal;
BitmapData bitmapData = bmpImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

本文介绍如何在C#项目中将Halcon的HObject图像转换为Bitmap格式,包括灰度图和彩色图的转换方法,适用于需要将Halcon处理后的图像显示在Windows Forms或WPF应用中。

1842

被折叠的 条评论
为什么被折叠?



