【发布时间】:2014-08-11 00:08:26
【问题描述】:
因为我之前的问题肯定不是很干净。并且分别我无法实现我的问题的确切解决方案。我一直在研究一个函数,它返回位于 X/Y 坐标中的像素的字节偏移量。为此,我有:
dword bmp_find_xy (dword xp, dword yp)
{
dword w = 50; // to clarify thats the real widh of the sample image i use
dword bpx = (3*8); // using 3*8 as a reminder.
dword offset = (2+sizeof(BMP)+sizeof(DIB)); // this is the offset 54.
dword pitch = w * 3; // determining the widh of pixels. Pitch variable
dword row = w * 3; // determining the widh of pixels. Row variable.
dword pixAddress; // result variable
if(pitch % 4 != 0) pitch += 4 - (pitch % 4); // finding the pitch (row+padding)
pixAddress = (offset) + pitch * yp + ((xp * bpx) / 8); // finding the address
return pixAddress;
}
所以问题不会像“我做错了什么/为什么我收到奇怪的错误”。问题是..我做得对吗?在第一次测试中,它似乎有效。但我有点不确定。一旦确认这是正确的方法..我将删除问题。
【问题讨论】:
-
我需要一堂关于位图理论的课程,因为我的知识当然不足以帮助你。
-
@FiddlingBits 这很容易,但确实令人困惑。顺便说一句,我不是母语……这让情况变得更糟。不……只是我不能发布整个项目。没有人能够编译它。它用于自定义引擎。
-
我没想到你不是以英语为母语的人,所以……没什么好担心的。 :-D
-
我正在尽力...
-
您正在硬编码
pitch,但有这样的声明:if(pitch % 4 != 0) ...;。这始终是正确的,因为 150 不能被 4 整除。