79830195

Date: 2025-11-25 22:24:34
Score: 1
Natty:
Report link

Thanks to @d4zed and @JonasH, I have a coloured image appearin!

The answer was twofold. In the code I posted, the "rgbx" needed to be replaced with "bgrx", and the PixelFormat needed to be extracted from the bitmap itself. This gives:

private HImage ToHImage(Bitmap bitmap)
{
    HImage ret = new();
    var bInfo = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
    ret.GenImageInterleaved(bInfo.Scan0, "bgrx", bitmap.Width, bitmap.Height, 0, "byte", 0, 0, 0, 0, -1, 0);
    bitmap.UnlockBits(bInfo);

    return ret;
}

However, the second problem was that I was using:

halconWindow.DispImage(hImage)

to display the image. This displays a greyscale image (yes, the documentation says this. I just didn't read it very well. My bad (and dumb name for a method)).

The correct method is:

halconWindow.DispColor(hImage)

The various HalconWIndow functions are here:

https://www.mvtec.com/doc/halcon/13/en/HWindow.html

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @and
  • Self-answer (0.5):
Posted by: Simon Parker