Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

bitmap

What is the easiest way to convert and save a 32-bit Bitmap to a 1-bit (black/white) .bmp file in C#?

like image 203
Dmi Avatar asked Apr 04 '10 13:04

Dmi


People also ask

How do I create a 32 bit bitmap?

Ctrl+Shift+S (Save As...) > choose . bmp > then a dialog comes up (BMP Options) asking you which type (16, 24 or 32 bit) and which file format (Windows or OS/2). Just tell it to use 32 bit and Windows then select ok.


1 Answers

The easiest way to do achieve this by using the Clone()

using System.Drawing.Imaging;

var original = //your source image;
var rectangle = new Rectangle(0, 0, original.Width, original.Height);

var bmp1bpp = original.Clone(rectangle, PixelFormat.Format1bppIndexed);

As disclaim this will maybe not the fastest way to do this there are much faster way's to do this

like image 82
WiiMaxx Avatar answered Sep 22 '22 08:09

WiiMaxx