Create a all black image and Cvb.ImageDrawer.FillCircle

Hi Sir:

I want to create a mask image like this.mask

Could you give me some example ? and help me to check my code below, thank you.

I have two questions:
1.How to use Stemmer cvb dll to create a black image?
2.I try to use Stemmer.Cvb.ImageDrawer.FillCircle function to draw fill circle on my image, but it also show this exception.

I try to use Stemmer.Cvb.ImageDrawer.FillCircle function to draw fill circle on my image, but it also show this exception.
draw circle exception

My C# Code:

private void CreateMask()
{
try
{
string filepath = “bb.bmp”;
Stemmer.Cvb.Image mask_image = Stemmer.Cvb.Image.FromFile(filepath);
mask_image.Initialize(0);

	Stemmer.Cvb.ImageDrawer.FillCircle(mask_image.Planes[0], 255, 50, 50, 10);

	mask_image.Save("mask with circle.bmp");
}
catch (Exception ee)
{
	MessageBox.Show(ee.ToString());
}

}

This is basically the same issue as with the DrawCircle method you had:

https://forum.commonvisionblox.com/t/stemmer-cvb-imagedrawer-drawcircle/1032/2?u=parsd

Here is the workaround for the FillCircle method:

public static class ImageDrawer
  {
    private const int AntiAliasOff = 0;
    private const int NormalDrawMode = 0;

    public static void FillCircle(Image image, RgbColor color, int centerX, int centerY, int radius)
    {
      FillCircle(image, new double[] { color.R, color.G, color.B }, centerX, centerY, radius);
    }

    public static void FillCircle(Image image, double[] intensity, int centerX, int centerY, int radius)
    {
      if (image == null)
        throw new ArgumentNullException(nameof(image));
      if (image.Planes.Count != intensity.Length)
        throw new ArgumentException("Intensity array length differs in regard to the number of planes", nameof(intensity));
      for (int i = 0; i < intensity.Length; ++i)
        FillCircle(image.Planes[i], intensity[i], centerX, centerY, radius);
    }

    public static void FillCircle(ImagePlane plane, double intensity, int centerX, int centerY, int radius)
    {
      int result = FillCircleInImage(plane.Parent.Handle, plane.Plane, centerX, centerY, radius, intensity, NormalDrawMode, AntiAliasOff);
      if (result < 0)
        throw CvbException.FromCvbResult(result);
    }

    [DllImport("CVCImg")]
    private static extern int FillCircleInImage(IntPtr image, int index, int centerX, int centerY, int radius, double intensity, int drawMode, int antiAliasMode);
  }
2 Likes