vc++实现图像放大、缩小、平移、旋转、各种哈哈镜变形
pImg1->imageData[i*pImg1->widthStep+j*pImg1->nChannels+k]=(uchar)pImg->imageData[int_srcY*pImg->widthStep+int_srcX*pImg->nChannels+k];
b=(bUpLeft*(1-float_srcX)*(1-float_srcY)+bUpRight*float_srcX*(1-float_srcY)+
rUpLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+2]; rUpRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+2]; rDownLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+2]; rDownRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+2];
unsigned char bUpLeft, bUpRight, bDownLeft, bDownRight; unsigned char gUpLeft, gUpRight, gDownLeft, gDownRight; unsigned char rUpLeft, rUpRight, rDownLeft, rDownRight; unsigned char b, g, r;
bUpLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+0]; bUpRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+0]; bDownLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+0]; bDownRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+0]; gUpLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+1]; gUpRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+1]; gDownLeft=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+1]; gDownRight=pImg->imageData[int_srcY*pImg->widthStep+int_srcX*3+1];
}
}
break;
// 双线性插值图像放大 case UPRESIZE:
size=cvSize(z*pImg->width,z*pImg->height); for(i=0;i<pImg1->height;i++)
for(j=0;j<pImg1->width;j++) {
float srcX=(float)(j*((float)pImg->width/(float)pImg1->width)); float srcY=(float)(i*((float)pImg->height/(float)pImg1->height)); int int_srcX=(int)srcX; int int_srcY=(int)srcY; float float_srcX=srcX-int_srcX; float float_srcY=srcY-int_srcY;
pImg1 = cvCreateImage(size,pImg->depth,pImg->nChannels);
bDownLeft*(1-float_srcX)*float_srcY+bDownRight*float_srcX*float_srcY);