问题描述
这是一个可以任意角度旋转位图的类,但是不知道如何调用,问题很基础,请各位大虾帮帮忙。刚接触VC++,请多多指教。以下是cpp文件:#include"StdAfx.h"#include"Xz.h"#include"windowsx.h"#include"math.h"#defineRADIAN(angle)((angle)*PI/180.0)//角度到弧度转化的宏#definePI3.1415926535CXz::CXz(void){}CXz::~CXz(void){GlobalFreePtr(m_pBitmapInfo);}voidCXz::Xuanzhuan(doubleRotateAngle){DWORDDstBufSize;LPBYTElpTempPtr,lpPtr,lpSrc,lpTemp;doubleSrcX1,SrcY1,SrcX2,SrcY2;doubleSrcX3,SrcY3,SrcX4,SrcY4;doubleDstX1,DstY1,DstX2,DstY2;doubleDstX3,DstY3,DstX4,DstY4;DWORDx0,y0,x1,y1;doublecosa,sina;doublenum1,num2;//角度到弧度的转化RotateAngle=(double)RADIAN(RotateAngle);cosa=(double)cos((double)RotateAngle);sina=(double)sin((double)RotateAngle);//原图的宽度和高度lpSrc=this->GetData();intWold=this->GetWidth();intHold=this->GetHeight();//原图的四个角的坐标SrcX1=(double)(-0.5*Wold);SrcY1=(double)(0.5*Hold);SrcX2=(double)(0.5*Wold);SrcY2=(double)(0.5*Hold);SrcX3=(double)(-0.5*Wold);SrcY3=(double)(-0.5*Hold);SrcX4=(double)(0.5*Wold);SrcY4=(double)(-0.5*Hold);//新图四个角的坐标DstX1=cosa*SrcX1+sina*SrcY1;DstY1=-sina*SrcX1+cosa*SrcY1;DstX2=cosa*SrcX2+sina*SrcY2;DstY2=-sina*SrcX2+cosa*SrcY2;DstX3=cosa*SrcX3+sina*SrcY3;DstY3=-sina*SrcX3+cosa*SrcY3;DstX4=cosa*SrcX4+sina*SrcY4;DstY4=-sina*SrcX4+cosa*SrcY4;//计算新图的宽度,高度intWnew=(DWORD)(max(fabs(DstX4-DstX1),fabs(DstX3-DstX2))+0.5);intHnew=(DWORD)(max(fabs(DstY4-DstY1),fabs(DstY3-DstY2))+0.5);//计算矩阵(2.9)中的两个常数,这样不用以后每次都计算了num1=(double)(-0.5*Wnew*cosa-0.5*Hnew*sina+0.5*Wold);num2=(double)(0.5*Wnew*sina-0.5*Hnew*cosa+0.5*Hold);if(m_pBitmapInfoHeader->biBitCount<9)//灰度图像{//将新的缓冲区中的每个字节都填成255,这样以后未处理的象素就是白色DstBufSize=Wnew*Hnew;lpTempPtr=newBYTE[Wnew*Hnew];memset(lpTempPtr,(BYTE)255,Wnew*Hnew);lpTemp=lpTempPtr;for(y1=0;y1<Hnew;y1++){for(x1=0;x1<Wnew;x1++){//x0,y0为对应的原图上的坐标x0=(DWORD)(x1*cosa+y1*sina+num1);y0=(DWORD)(-1.0f*x1*sina+y1*cosa+num2);if((x0>=0)&&(x0<Wold)&&(y0>=0)&&(y0<Hold))//在原图范围内{lpPtr=lpSrc+y0*Wold+x0;lpTempPtr=lpTemp+y1*Wnew+x1;*lpTempPtr=*lpPtr;//进行象素的复制lpTempPtr=lpTemp;}}}this->SetWidth(Wnew);this->SetHeight(Hnew);this->m_pData=lpTemp;}else//24位彩色{//将新的缓冲区中的每个字节都填成255,这样以后未处理的象素就是白色DstBufSize=Wnew*Hnew*3;lpTempPtr=newBYTE[Wnew*Hnew*3];memset(lpTempPtr,(BYTE)255,Wnew*Hnew*3);lpTemp=lpTempPtr;for(y1=0;y1<Hnew;y1++){for(x1=0;x1<Wnew;x1++){//x0,y0为对应的原图上的坐标x0=(DWORD)(x1*cosa+y1*sina+num1);y0=(DWORD)(-1.0f*x1*sina+y1*cosa+num2);if((x0>=0)&&(x0<Wold)&&(y0>=0)&&(y0<Hold))//在原图范围内{lpPtr=lpSrc+y0*Wold*3+x0*3;lpTempPtr=lpTemp+y1*Wnew*3+x1*3;*lpTempPtr++=*lpPtr++;//进行象素的复制*lpTempPtr++=*lpPtr++;//进行象素的复制*lpTempPtr=*lpPtr;//进行象素的复制lpTempPtr=lpTemp;}}}this->SetWidth(Wnew);this->SetHeight(Hnew);this->m_pData=lpTemp;}}voidCXz::clearmem2(){LONGtemp;temp=m_pBitmapInfoHeader->biHeight;m_pBitmapInfoHeader->biHeight=m_pBitmapInfoHeader->biWidth;m_pBitmapInfoHeader->biWidth=temp;}UINTCXz::GetWidth(){return(UINT)m_pBitmapInfoHeader->biWidth;}UINTCXz::GetHeight(){return(UINT)m_pBitmapInfoHeader->biHeight;}BYTE*CXz::GetData(){returnm_pData;}BITMAPINFO*CXz::GetInfo(){returnm_pBitmapInfo;}voidCXz::SetWidth(UINTwidth){m_pBitmapInfoHeader->biWidth=width;}voidCXz::SetHeight(UINTheight){m_pBitmapInfoHeader->biHeight=height;}
解决方案
解决方案二:
帮顶吧。vc不懂