how to rotate a bitmap image in c++ using MFC? i dont wanna use GDI. is it possible by only changing x and y values in this code?
CBitmap img;
开发者_JS百科 CDC dc;
BITMAP bmp;
img.LoadBitmapW(IDB_BITMAP1);
img.GetBitmap(&bmp);
CDC* pDC = this->GetDC();
dc.CreateCompatibleDC(pDC);
CBitmap* pOld = dc.SelectObject(&img);
for(int y = 0; y < bmp.bmHeight; y++)
{
for(int x = 0; x < bmp.bmWidth; x++)
{
COLORREF rgb = dc.GetPixel(x, y);
BYTE r = GetRValue(rgb);
BYTE g = GetGValue(rgb);
BYTE b = GetBValue(rgb);
dc.SetPixel(x, y, RGB(r,g,b));
}
}
pDC->BitBlt(200, 200, bmp.bmWidth, bmp.bmHeight, &dc, 0, 0, SRCCOPY);
dc.SelectObject(pOld);
please someone reply soon, as this is the last day to work on project, tommorrow is its submission.
Asking about doing drawing with MFC but not using GDI is a bit like asking about how to go swimming without getting wet. As far as drawing goes, MFC is a thin wrapper around GDI, so anything you do with MFC gets translated quite directly to GDI with just a bit of syntactic sugar added (and in this area, the amount of syntactic sugar was based on a diabetic's diet).
That said, yes, exchanging x
and y
in your loops could do roughly the right thing (depending on the direction of rotation you want, for one thing) -- though in all honesty you should think really hard about scrapping that code completely. You're using SetPixel (i.e., GDI) to do the drawing in any case; there are lots better ways to do it than this (from the looks of things, you could benefit immensely from CreateDIBSection
).
精彩评论