VC6.0图形处理5--几何变换
2011-08-31 23:38 libing64 阅读(274) 评论(0) 编辑 收藏 举报源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522
//注意如何申请新的存储空间,存放处理后的图片,并利用memcpy,将数据copy给原来存储图像的结构
void CBMPViewerDoc::OnMenuitem32788() //缩小变换
{// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
int i0 , j0;
double ratio = 0.5;
//申请存储空间,并返回指针给lpTemp
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );HLOCAL hTemp;
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char * lpDest;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp+linewidth*(bi.biHeight - i -1) + j;
i0 = (LONG)(i /ratio +0.5);
j0 = (LONG)(j /ratio + 0.5);
if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
*lpDest = *lpScr;
}
else {
*lpDest = 255;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32789() //放大变换
//只能实现图像区域不变的放大,还不能改变图像的大小
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
int i0 , j0;
double ratio = 2; //放大倍数
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp+linewidth*(bi.biHeight - i -1) + j;
i0 = (LONG)(i /ratio +0.5);
j0 = (LONG)(j /ratio + 0.5);
if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
*lpDest = *lpScr;
}
else {
*lpDest = 255;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32784() //旋转变换
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
int i0 , j0;
double RotateAngle = 15; //旋转角度
double piRotateAngle = RotateAngle * PI/180;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp+linewidth*(bi.biHeight - i -1) + j;
i0 = (LONG)(cos(piRotateAngle) * i- sin(piRotateAngle) *j + 0.5);
j0 = (LONG)(sin(piRotateAngle) *i + cos(piRotateAngle) * j +0.5);
if((i0 >= 0) && (i0 < bi.biHeight)&&(j0 >= 0 ) && (j0 < bi.biWidth)){
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i0 -1) + j0;
*lpDest = *lpScr;
}
else {
*lpDest = 255;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}