|
3驿站币
// 计算图像每行的字节数
lLineBytes = (((wide * 8) + 31) / 32 * 4);
// 暂时分配内存,以保存新图像
temp = new BYTE[lLineBytes*height];
// 初始化新分配的内存,设定初始值为255 (白色)
lpDst = (LPBYTE)temp;
memset(lpDst, (BYTE)255, lLineBytes * height);
// 每行
for (i = 0; i < wide; i++)
{
// 每列
for (j = 0; j < height; j++)
{
// 计算该象素在源DIB中的坐标 位图是从左下角开始扫描(左向右 下向上)
lpSrc = (LPBYTE)p_data + lLineBytes * (height - 1 - j) + i;
int i0, j0;
// 计算该象素在新DIB中的坐标
i0 = i + m_xMove;
j0 = j + m_yMove;
// 判断是否在新图范围内
if ((i0 >= 0) && (i0 < wide) && (j0 >= 0) && (j0 < height))
{
lpDst = (LPBYTE)temp + lLineBytes *(height - 1 - j0) + i0;
// 复制象素
*lpDst = *lpSrc;
}
else
{
// 对于源图中没有的象素,直接赋值为255
*((unsigned char*)lpDst) = 255;
}
}
}
// 复制平移后的图像
memcpy(p_data, temp, lLineBytes * height);
// 释放内存
delete temp;
} |
上一篇: 数据库班下一篇: mfc 单文档程序如何使用edit控件,static控件
|