Converting 1 bit image to 8 bit
Disclaimer: I don't know C #, but I have handled too much image processing in C / C ++, so I can't seem to convey an answer - I'll answer in C, since I think C # has a similar syntax.
Both 1 bit (two colors) and 8 bit (256 colors) images have a palette. but going to jump from 1 to 8 bits is easy - since there is no quantization, just up-fetch.
First you need to select (or import) two colors of the 1 bit image palette. If you don't have them, I suggest using black (0x000000FF) and white (0xFFFFFFFF) for clarity (note: both are RGBA colors, I think windows use ABGR). This will be your "palette".
Then display each color in a palette. The input image will have a width * height / 8
byte. Each byte represents eight pixels. Since I donโt know about your experience with bittwiddling (i.e. I donโt want to confuse you, and I donโt want you to mindlessly copy and paste the code that is provided to you on the internet), I will keep this answer simple.
// Insert your image attributes here
int w = image.width;
int h = image.height;
// Data of the image
u8* data = image.data;
/*
* Here, you should allocate (w * h) bytes of data.
* I'm sure C# has ByteArray or something similar...
* I'll call it output in my code.
*/
u8* output = new u8[w * h];
u8* walker = output;
// Loop across each byte (8 pixels)
for(int i=0; i<w*h/8; ++i) {
// Loop across each pixel
for(int b=(1<<7); b>0; b>>=1) {
// Expand pixel data to output
*walker++ = !!(data[i] & b);
}
}
Hope it helps!
source to share
Does this help:
http://www.wischik.com/lu/programmer/1bpp.html
But of course this requires some cleaning. He can use some attempts. Finally, for all DC deletions and release
source to share