我写了一个图像水平镜像翻转的函数
但使用后,图像会翻转,但图像的颜色发生了变化
不知是何缘故,请各位大虾指教!!!
源函数如下:
BOOL WINAPI FanZDIB(LPSTR lpDIBBits,LONG lWidth,LONG lHeight,BOOL bDirection)
{
LPSTR lpSrc; //指向源图像的指针
LPSTR lpDst; //指向复制区域的指针 LPSTR lpBits; //指向复制图像的指针
HLOCAL hBits; LONG i,j;
LONG lLineBytes; //图像每行的字节数 //计算图像每行的字节数
lLineBytes = WIDTHBYTES(lWidth*24); //24指的是24bit位图
//暂时分配内存,以保持一行图像数据
hBits=LocalAlloc(LHND,lLineBytes);
if (hBits==NULL)
{
return FALSE;
} lpBits = (char * )LocalLock(hBits); //水平翻转
// 针对图像每行进行操作
for(i = 0; i < lHeight; i++)
{
// 针对每行图像左半部分进行操作
for(j = 0; j < lWidth / 2; j++)
{
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j; lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1);
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits;
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j+1;
lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1)+1;
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits;
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j+2;
lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1)+2;
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits; }
}
LocalUnlock(hBits);
LocalFree(hBits);
return TRUE;
}
但使用后,图像会翻转,但图像的颜色发生了变化
不知是何缘故,请各位大虾指教!!!
源函数如下:
BOOL WINAPI FanZDIB(LPSTR lpDIBBits,LONG lWidth,LONG lHeight,BOOL bDirection)
{
LPSTR lpSrc; //指向源图像的指针
LPSTR lpDst; //指向复制区域的指针 LPSTR lpBits; //指向复制图像的指针
HLOCAL hBits; LONG i,j;
LONG lLineBytes; //图像每行的字节数 //计算图像每行的字节数
lLineBytes = WIDTHBYTES(lWidth*24); //24指的是24bit位图
//暂时分配内存,以保持一行图像数据
hBits=LocalAlloc(LHND,lLineBytes);
if (hBits==NULL)
{
return FALSE;
} lpBits = (char * )LocalLock(hBits); //水平翻转
// 针对图像每行进行操作
for(i = 0; i < lHeight; i++)
{
// 针对每行图像左半部分进行操作
for(j = 0; j < lWidth / 2; j++)
{
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j; lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1);
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits;
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j+1;
lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1)+1;
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits;
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j+2;
lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1)+2;
*lpBits = *lpDst;
*lpDst = *lpSrc;
*lpSrc = *lpBits; }
}
LocalUnlock(hBits);
LocalFree(hBits);
return TRUE;
}
解决方案 »
- 新手学vc,想找一个第3方的播放MP4的sdk,请问什么地方可以找到。
- VC2005由于应用程序配置不正确。。。。。
- 怎样检查CBitmap类加载的资源与某一资源是否相同?
- 简单问题,CString的问题
- 寻求高手。怎样实现局域网中对其他机子的监控和控制??
- 新手求助:5个问题,关于SPLITTER和RICHEDIT,各位请进!!
- connect成功后改变IP,connect断开了么?
- 如何用程序删除桌面的快捷方式和“开始--程序--XXX”的项。 3x
- ShowDialog()的参数
- 你以为你真的精通 C++ 吗 -- 回答下面的问题再说吧!
- 菜问题:别处的代码拿来无法设置断点
- 用ODBC存储和读取Excel数据表
lpSrc = (char *)lpDIBBits + lLineBytes * i + 3*j;
lpDst = (char *)lpDIBBits + lLineBytes * (i + 1) - 3*(j+1);
LPSTR 究竟指的是几位的值!?
*lpBits 是几位的数看你的程序,一次只交换一个字节的值,
会不会是这里有问题,试试 BYTE *