我试图找出如何在C++ VS中创建位图文件.目前我已经接受了文件名并添加了".bmp"扩展名来创建文件.我想知道如何通过将文件变成不同的颜色或图案来改变文件的像素(例如像棋盘一样)这是我的功能,我相信我必须一次发送3个不同的字节为了建立像素的颜色.
void makeCheckerboardBMP(string fileName, int squaresize, int n) {
ofstream ofs;
ofs.open(fileName + ".bmp");
writeHeader(ofs, n, n);
for(int row = 0; row < n; row++) {
for(int col = 0; col < n; col++) {
if(col % 2 == 0) {
ofs << 0;
ofs << 0;
ofs << 0;
} else {
ofs << 255;
ofs << 255;
ofs << 255;
}
}
}
}
void writeHeader(ostream& out, int width, int height){
if (width % 4 != 0) …Run Code Online (Sandbox Code Playgroud)