We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How To Convert RGB 24-bit Bitmap To Monochrome Bitmap?

I would like to create a new image which open an existing 24-bit depth color Bitmap and add some text. Is there any method I can output the image as monochrome bitmap?

Hi Frankie,


Thank you for contacting Aspose support.

You can opt a similar approach as outlined below to change any polychrome bitmap to monochrome.

C#

using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(myDir + “sonic.bmp”))
{
//Initialize an instance of BmpOptions and set various properties
Aspose.Imaging.ImageOptions.BmpOptions outputSettings = new Aspose.Imaging.ImageOptions.BmpOptions();
outputSettings.BitsPerPixel = 1;
//Set the Palette property to an array of Colors that will replace the existing image colors
outputSettings.Palette = new Aspose.Imaging.ColorPalette(new[] { Aspose.Imaging.Color.Black, Aspose.Imaging.Color.White });
//Save the result to disc by passing instance of BmpOptions
image.Save(myDir + “output.bmp”, outputSettings);
}

If you wish to write some text on the image canvas, you can use DrawString of the Graphics class for your requirements. Below provided code snippet demonstrates the usage.

C#
//Initialize Graphics class to draw a string Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image); //Call DrawString with appropriate settings graphics.DrawString("Hello World", new Aspose.Imaging.Font("Ariel", 10), new Aspose.Imaging.Brushes.SolidBrush(Color.Black), new PointF(100, 100));
Please feel free to write back in case you have further questions for us.