EVC位图旋转
谁做过位图旋转啊?我的怎么老不实现啊?也不知道代码哪里有问题。
谁有方法啊?源代码更好啊。
我已经知道bmp图片旋转应该问题不大啊?
CClientDC hDC(this);
double x1,x2,x3;
double y1,y2,y3;
double maxWidth,maxHeight,minWidth,minHeight;
double srcX,srcY;
double sinA,cosA;
double DstWidth;
double DstHeight;
HDC dcDst;//ÐýתºóµÄÄÚ´æÉ豸»·¾³
HBITMAP newBitmap;
sinA = sin(angle);
cosA = cos(angle);
x1 = -SrcHeight * sinA;
y1 = SrcHeight * cosA;
x2 = SrcWidth * cosA - SrcHeight * sinA;
y2 = SrcHeight * cosA + SrcWidth * sinA;
x3 = SrcWidth * cosA;
y3 = SrcWidth * sinA;
minWidth = x3> (x1> x2?x2:x1)?(x1> x2?x2:x1):x3;
minWidth = minWidth> 0?0:minWidth;
minHeight = y3> (y1> y2?y2:y1)?(y1> y2?y2:y1):y3;
minHeight = minHeight> 0?0:minHeight;
maxWidth = x3> (x1> x2?x1:x2)?x3:(x1> x2?x1:x2);
maxWidth = maxWidth> 0?maxWidth:0;
maxHeight = y3> (y1> y2?y1:y2)?y3:(y1> y2?y1:y2);
maxHeight = maxHeight> 0?maxHeight:0;
DstWidth = maxWidth - minWidth;
DstHeight = maxHeight - minHeight;
dcDst = CreateCompatibleDC(dcSrc);
newBitmap = CreateCompatibleBitmap(dcSrc,(int)DstWidth,(int)DstHeight);
SelectObject(dcDst,newBitmap);
for( int I = 0 ;I <DstHeight;I++)
{
for(int J = 0 ;J < DstWidth;J++)
{
srcX = (J + minWidth) * cosA + (I + minHeight) * sinA;
srcY = (I + minHeight) * cosA - (J + minWidth) * sinA;
if( (srcX > = 0) && (srcX <= SrcWidth) &&(srcY > = 0) && (srcY <= SrcHeight))
{
BitBlt(dcDst, J, I, 1, 1, dcSrc,(int)srcX, (int)srcY, SRCCOPY);
}
}
}
//ÏÔʾÐýתºóµÄλͼ
BitBlt(hDC,34,26,(int)DstWidth,(int)DstHeight,dcDst,0,0,SRCCOPY);
DeleteObject(newBitmap);
DeleteDC(dcDst);
哪里不对啊?
请各位大虾给点代码啊。谢谢
[解决办法]
用变换矩阵做很容易实现的。有变换公式你找一下就好了