问题描述
大家好..
我有一个要求.我必须旋转上面涂有位图的DC.但是我不知道该怎么做?下面是示例代码:
///////////////////////////////
HBITMAP m_hBitmapSmall;
CString m_csBitmap;
m_csBitmap ="c://Aircraft.bmp";
m_hBitmapSmall =(HBITMAP)LoadImage(NULL,m_csBitmap.GetBuffer(m_csBitmap.GetLength()),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
int iFrameWidth = 37,iFrameHeight = 37;
CBitmap * pBmp =新的CBitmap();
CDC tempDC;
tempDC.CreateCompatibleDC(NULL);
tempDC.SetBkMode(TRANSPARENT);
pBmp-> CreateCompatibleBitmap(& tempDC,iFrameWidth,iFrameHeight);
tempDC.SelectObject(pBmp);
CBitmap * pIconBitmap;
pIconBitmap = CBitmap :: FromHandle(m_hBitmapSmall);
CDC tempIconDC;
tempIconDC.CreateCompatibleDC(NULL);
tempIconDC.SetBkMode(TRANSPARENT);
tempIconDC.SelectObject(pIconBitmap);
tempDC.PatBlt(0,0,iFrameWidth,iFrameHeight,BLACKNESS);
tempDC.BitBlt(0,0,iFrameWidth,iFrameHeight,& tempIconDC,0,0,SRCCOPY);//现在您在tempDC上具有位图,因此请使用它.
//在最终发条之前旋转tempDC
//这里需要帮助...
//将tempDC转换为最终DC
pDC-> BitBlt(0,0,iFrameWidth,iFrameHeight,& tempDC,0,0,SRCCOPY); //原始位图
/////////////////////////////////////////////////////
在上面的代码中,在最后一行的tempDC被抹平为(文档视图体系结构的)pDC的最后一行之前,我想根据给定的角度旋转tempDC. Aircraft.bmp是飞机的小型37x37 bmp.因此,当我旋转tempDC时,飞机将自动旋转,因为它已经被粘在tempDC上了.我尝试了几种方法,但是形状是剪切的,这是无法承受的.我每次都无法旋转Aircraft.bmp,因为我一开始就将其加载一次,然后在我收到一个角度时想旋转它.有人可以帮忙吗?我将非常感谢您的帮助...
Hello every one..
I have a requirement. I have to rotate a dc that has a bitmap blitted on it. But i dont know how to do it? Below is the sample code:
////////////////////////////////////////////
HBITMAP m_hBitmapSmall;
CString m_csBitmap;
m_csBitmap = "c://Aircraft.bmp";
m_hBitmapSmall = (HBITMAP)LoadImage(NULL,m_csBitmap.GetBuffer(m_csBitmap.GetLength()),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
int iFrameWidth = 37, iFrameHeight = 37;
CBitmap* pBmp = new CBitmap();
CDC tempDC;
tempDC.CreateCompatibleDC(NULL);
tempDC.SetBkMode(TRANSPARENT);
pBmp->CreateCompatibleBitmap(&tempDC,iFrameWidth,iFrameHeight);
tempDC.SelectObject(pBmp);
CBitmap *pIconBitmap;
pIconBitmap = CBitmap::FromHandle(m_hBitmapSmall);
CDC tempIconDC;
tempIconDC.CreateCompatibleDC(NULL);
tempIconDC.SetBkMode(TRANSPARENT);
tempIconDC.SelectObject(pIconBitmap);
tempDC.PatBlt(0,0,iFrameWidth,iFrameHeight,BLACKNESS);
tempDC.BitBlt(0,0,iFrameWidth,iFrameHeight,&tempIconDC,0,0,SRCCOPY);//now u have the bitmap on tempDC, so play with it.
//rotate tempDC before final blitting
//help required here...
//blit the tempDC to final DC
pDC->BitBlt(0,0,iFrameWidth,iFrameHeight,&tempDC,0,0,SRCCOPY);//original bitmap
//////////////////////////////////////////////////
In the above code, before teh last line of blitting where tempDC is blitted to pDC (of the document view architecture), i want to rotate the tempDC according to a given angle. The Aircraft.bmp is a small 37x37 bmp of an aircraft. so when i rotate the tempDC, the aircraft will be rotated automatically, as it is already blitted to the tempDC. i have tried few methods, but the shape is shearing, which is not affordable. I cant roatate the Aircraft.bmp each time, as i load it once on the beginning and then want to rotate it as i receive an angle. can anyone help? I''ll be thankful for help...
推荐答案
这篇关于如何旋转直流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!