首页 > 解决方案 > 将数组写入位图c ++

问题描述

我再次将数组写入位图时遇到了麻烦,所以基本上我从 .bmp 文件中读取数据,在该文件中我获取像素数据,我想让 B 和 R = 0 所以这是我的代码:

int row_padded = ( Picture.biWidth*3 + 3) & (~3);
unsigned char* data = new unsigned char [row_padded];
unsigned char tmp;
 for(int i = 0; i < Picture.biHeight; i++)
{
    fread(data, sizeof(unsigned char), row_padded, plik);
    for(int j = 0; j < Picture.biWidth*3; j += 3)
    {
        data[j] = 0;
        data[j+2] = 0;

    }
}

现在当我有我的 B 和 R = 0 时,我想再次将它保存到同一个文件中,所以我正在使用:

for(int j = 0; j< Picture.biHeight; j++)
{
    fwrite(data,1,Picture.biWidth, f);
}

但没有任何效果。

标签: c++bitmap

解决方案


fwrite(data,1,Picture.biWidth, f)一定是fwrite(data,1,row_padded, f)没有?否则只写入前三分之一的字节

注意:根据定义sizeof(unsigned char)是 1


推荐阅读