CImg CImg::operator | (CImg& gray) { CImg grayRet = *this; int nHeight = GetHeight(); int nWidth = GetWidthPixel(); if(nHeight != gray.GetHeight()) { AfxMessageBox("计算或运算的两幅图像必须具有相同的大小!运算失败,返回原图像。"); return grayRet; } if(nWidth != gray.GetWidthPixel()) { AfxMessageBox("计算或运算的两幅图像必须具有相同的大小!运算失败,返回原图像。"); return grayRet; } // 两幅图像的或 for(int i=0; i<nHeight; i++) { for(int j=0; j<nWidth; j++) { if(gray.GetGray(j, i) == 0) grayRet.SetPixel(j, i, RGB(0, 0, 0)); } } return grayRet; }
BOOL CImg::operator == (CImg& gray) { int nHeight = GetHeight(); int nWidth = GetWidthPixel(); if(nHeight != gray.GetHeight()) return false; if(nWidth != gray.GetWidthPixel()) return false; for(int i=0; i<nHeight; i++) { for(int j=0; j<nWidth; j++) { if( GetGray(j, i) != gray.GetGray(j, i) ) return false; } } return true; }
CImg* CDimageView::Move(int x, int y ,bool ifresize, CImg* pImg) { CImg* newImg = new CImg(*pImg); //改变新图像大小 int old_width,old_height,width,height; width=old_width=newImg->GetWidthPixel(); height=old_height=newImg->GetHeight(); //if(!ifunchange) //{ // width=old_width+x; // height=old_height+y; // if((width<=0)||(height<=0)) // { // CString test("妈呀,图都被你整没了!"); // CString title("数值有误"); // MessageBox(test,title,0); // return NULL; // } //} if(ifresize) { width=old_width+x; height=old_height+y; newImg->ImResize(height,width); } int i0,j0,i,j; COLORREF color; for(i=0;i<width;i++) for(j=0;j<height;j++) { i0=i-x;j0=j-y; if((i0>=0)&&(i0<old_width)&&(j0>=0)&&(j0<old_height)) { color=pImg->GetPixel(i0,j0); } else { color=RGB(255,255,255); //if(!ifunchange) // color=RGB(255,255,255); //else //{ // if(!ifloop) // color=RGB(255,255,255); // else // { // i0=i0%width; // j0=j0%height; // if(i0<0) // i0+=width; // if(i0>=width) // i0-=width; // if(j0<0) // j0+=height; // if(j0>=height) // j0-=height; // color=pImg->GetPixel(i0,j0); // } //} } newImg->SetPixel(i,j,color); } return newImg; }