我写了一个图像水平镜像翻转的函数
但使用后,图像会翻转,但图像的颜色发生了变化
不知是何缘故,请各位大虾指教!!!
源函数如下:
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;
}