.net - 如何在灰色位图图像上绘制彩色形状?

标签 .net opencv graphics bitmap emgucv

我有灰色的位图图像。

       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);

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

无法从具有索引像素格式的图像创建Graphics对象。

知道如何在灰色位图图像上绘制彩色形状吗?
先感谢您!

最佳答案

转换为Bgr(RGB),然后尝试代码。

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

关于.net - 如何在灰色位图图像上绘制彩色形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15989760/

相关文章:

c# - ConfigurationManager.AppSettings - 如何修改和保存?

c# - 找不到“Newtonsoft”

qt - 保存和加载向量<Mat> Qt & OpenCV

c# - 绘制的矩形仅出现在我的 userControl 的最后一个实例上

javascript - 用户认证查询

.net - .net TransactionScope 是否处理非常复杂的数据库事情?

python - 提高 OpenCV Python 中 findContour 的准确性

c# - DLL 'cvCreateContourTree'中的 'opencv_imgproc231'-已弃用?

VB.Net 背景渐变使用 LinearGradientBrush 和显示图像

math - 求解向量的原点