好多年不写了,这几天做项目遇到个烦死的问题,大周末的终于解决了。
用Halcon转换成C#时 Hobject对象如何转换成我们认识的Bitmap呢,搞了两天终于好了。
上代码。麻麻再也不用担心我的转换问题了。
private void GenertateGrayBitmap(HObject image, out Bitmap res)
{
HTuple hpoint, type, width, height;
const int Alpha = 255;
int[] ptr = new int[2];
HOperatorSet.GetImagePointer1(image, out hpoint, out type, out width, out height);
res = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
ColorPalette pal = res.Palette;
for (int i = 0; i <= 255; i++)
{
pal.Entries[i] = Color.FromArgb(Alpha, i, i, i);
}
res.Palette = pal;
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapData = res.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);