我如何在灰色位图图像上绘制彩色形状



我有一个灰色的位图图像。

       Image<Gray, byte> cannyImage = new Image<Gray, byte>(pathImg);
       Bitmap drawImg = cannyImage.ToBitmap();

我想在这个图像上画一些形状:

    Graphics g = Graphics.FromImage(drawImg);
    g.DrawLines(new Pen(Color.Purple), shapes[0].sample.pointsArray);

在代码的最后一行,我得到这个错误:

不能从具有索引像素格式的图像创建图形对象。

任何想法如何我可以绘制彩色形状在灰色位图图像?提前感谢!

转换成Bgr (RGB),然后给你的代码一个尝试。

Image<Bgr, Byte> cannyBgr = cannyImage.Convert<Bgr, Byte>();
Bitmap drawImg = cannyBgr.ToBitmap();

最新更新