VC6.0图像处理4镜像

源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

//本节是关于镜像处理的函数,大家重点关注如何申请存储空间,并返回一个指向该空间的指针,以及如何利用指针实现数据的操作

void CBMPViewerDoc::OnMenuitem32786() //垂直镜像
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;

 //申请空间,并返回其指针赋给lpbit

              HLOCAL  hbit;
   hbit = LocalAlloc(LHND, linewidth);
            unsigned char *lpbit;
   lpbit = (unsigned char*)LocalLock(hbit);



unsigned char *lpScr;
unsigned char * lpDest;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight/2 ; i++){


lpScr = (unsigned char*)lpBuf + linewidth*i;
lpDest = (unsigned char*)lpBuf+linewidth*(bi.biHeight- 1 - i);

//常用的函数memcpy,将制定大下的数据从地址2复制个地址1

memcpy(lpbit, lpDest, linewidth);

memcpy(lpDest, lpScr,linewidth);
memcpy(lpScr, lpbit,linewidth);


}

// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}

void CBMPViewerDoc::OnMenuitem32787() //水平镜像
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
unsigned char * lpDest;
    unsigned char temp;

// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth/2 ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;
       lpDest = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i) - j;
temp = *lpScr;
*lpScr = *lpDest;
*lpDest = temp;

}

}



UpdateAllViews(NULL,0,NULL);

}

//未完待续

原文地址:https://www.cnblogs.com/libing64/p/2878773.html