c++8位bmp转1位
void Commom::Bitmap_8To1(char* src , int width, int height )
{ int widthStep = (width + 31) / 32 * 4;
char* data =(char*) malloc(widthStep*height);
memset(data, 0, (width + 31) / 32 * 4 * height);
//单色位图,1表示白色,0表示黑色,结果图背景为白(1),线条为黑(0)
for (int i = 0; i < height; i++)
{
for (int j = 0; j < widthStep; j++)
{
char temp_data = 0;
for (int k = 0; k < 8; k++)
{
if (j * 8 + k < width)
{
int temp_value = 0;
//if ((BYTE)src[(height - 1 - i)*width + j * 8 + k] == 255)
if ( (BYTE) src[ ( i)*width + j * 8 + k] == 255)
{
temp_value = 1 << (7 - k);
temp_data += temp_value;
}
}
}
data[i*widthStep + j] = temp_data;
}
}
memcpy(src, data, widthStep*height);
free( data);
}