如何向位图添加填充字节?
假设我有一些栅格数据想要写入文件。现在我想将其写入为 bmp 文件。
该数据恰好不是 DWORD 对齐的,如果我理解正确的话,需要填充足够的数据字节到达下一个 DWORD ..
但是,当我尝试用以下代码填充它时:
bmFile.Write(0x0, (4-(actualWidth%4)));
我收到错误..如果我尝试调试(我使用的是 MSVC++ 6.0),则下一个语句指向 CFile 中的 ASSERT: :Write 断言第一个参数为 NULL.. 所以失败了..
我应该如何填充它? 我应该写成:
bmFile.Write("0x0"(4-(actualWidth%4)));
吗? 或者这会按字面意思处理...?
谢谢..
Lets say I have some raster data I want to write to a file.. Now I want to write it as a bmp file..
This data happens to be not DWORD aligned, which, if I understand correctly, needs to be padded with enough bytes to reach the next DWORD..
However, when I try to pad it with this code:
bmFile.Write(0x0, (4-(actualWidth%4)));
I get an error.. If I try to debug (I'm using MSVC++ 6.0), the next statement points to an ASSERT in CFile::Write that asserts the first parameter is NULL.. So this fails..
How should I pad it? should I write out:
bmFile.Write("0x0"(4-(actualWidth%4)));
instead? or would this be treated literally...?
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许尝试一下:
正如您所说,您的第一个示例是尝试写入空指针指向的数据。 您的第二个示例将从字节“0”、“x”、“0”写入,这些字节的 ASCII 值为 0x30、0x78、0x30,这可能不是您想要的。
Perhaps try:
Your first example is, as you say, trying to write data pointed to by a null pointer. Your second example would write from the bytes '0', 'x', '0' which have ASCII values 0x30, 0x78, 0x30, which is probably not what you intend.