Search code examples
c#imagegraphicsmonochrome

Saving a Drawn Image as MonoChrome


Hi everyone i have a image that i draw using graphics.drawline

Bitmap Signature = new Bitmap(x, y);
   Graphics g;
                            g = Graphics.FromImage(Signature);
                            //MessageBox.Show(cord.Length.ToString());
                            Pen mypen = new Pen(Brushes.Black);
                            mypen.Width = 2;
                            mypen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
                            mypen.StartCap = System.Drawing.Drawing2D.LineCap.Square;

anyways

Signature.Save(filename);

this works great i am trying to make this image monochrome i have tried many different solutions such as this

Save a 32-bit Bitmap as 1-bit .bmp file in C#

also as soon as i reference the imagetype.bmp it turns black any ideal or suggestions on this, i ran the above link like this

Bitmap converted = BitmapTo1Bpp(Signature);
converted.Save(filename);

but the resulting picture is always pure black can someone please help me save this as a monochrome image


Solution

  • After more searching i found that

    g = Graphics.FromImage(Signature);
    g.Clear(Color.White);
    

    Adding a White Background to the Graphics Drawing Fixed The Problem