QImage::Format_Mono 為通常所講的位圖模式, QT中本提供了 QBitmap 來作為位圖相關的應用, 但其最大弊端在於無法操作圖片中 pixel 本身或說相關方法太過繁瑣。
Mono 由於 1 bit 存儲 1 pixel , 其在內存中即 8 pixel 1 個字節存放(還有 4 字節對齊)。 故存放策略又分 MSB(means the first pixel will be stored in most significant bit of the first byte:高位在前,理解為大端)與LSB(小端)模式。
Format_Mono 默認為大端模式, 可用默認的 pixel() 和 setPixel() 方法直接操作(當然代價龐大)。
1 int getPixel(const QImage img, const int col, const int row) 2 { 3 const uchar uMask = 0x80 >> (col % 8); 4 return img.scanLine(row)[col / 8] & uMask ? 1 : 0; 5 }
上述代碼摘自 stackoverflow 上一回復,個人覺得更易於理解 Mono 格式的數據存儲方式