c++ - 将数组写入位图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);
}
但没有任何效果。
解决方案
fwrite(data,1,Picture.biWidth, f)
一定是fwrite(data,1,row_padded, f)
没有?否则只写入前三分之一的字节
注意:根据定义sizeof(unsigned char)
是 1
推荐阅读
- typescript - 如何从 Typescript 映射中转换 JSON 对象?
- java - 如何使用 JUnit 对时间相关方法进行单元测试
- javascript - scrollTop x % of total
- angular - 如何修复'错误:无法匹配任何路由。URL 段:'anythongs''
- asp.net-mvc - 使用ajax调用的异步操作的mvc进度
- javascript - 自定义地图图标可以替换现有的吗?
- c# - 如何在.Net core 的测试中检查方法是否递归?
- c# - 等待异步下载完成
- python - CycleGAN - 工件和风格不转移
- php - 将 HTML 网页连接到 SQL Server