Solved

Best way to rotate a CBitmap image

Posted on 1997-03-01
1
1,200 Views
Last Modified: 2013-11-20
I need to rotate a CBitmap that may have any number of colors in it depending on the current system color palette. It needs to be turned 90 degrees counter-clockwise.  What is the best way to do this? I'm using Visual C++ 4.1 in NT 4.0 and Win95.

Sample code would be very appreciated!
0
Comment
Question by:Guy012897
1 Comment
 
LVL 1

Accepted Solution

by:
xbwen earned 200 total points
Comment Utility
Hi:
  I used to do something like that, what I did is create a memory
DC to save the transfered the bitmap, then use BitBlt copy to screenDC, the transfer is:

   CDC bmpDC,memDC;
   bmpDC.CreateCompatibleDC(&dc);  
   memDC.CreateCompatibleDC(&dc);
   CBitmap *oldmBmp,trs_Bmp,*oldtBmp;
   trs_Bmp.CreateCompatibleBitmap(&dc,cxDIB,cyDIB);
   oldmBmp=bmpDC.SelectObject(&org_Bmp);
   oldtBmp=memDC.SelectObject(&trs_Bmp);    

   for (int y=0;y<cyDIB;y++)
    for (int x=0;x<cxDIB;x++)
         memDC.StretchBlt(y,cyDIB-x,1,1,&bmpDC,x,y,1,1,SRCCOPY);
   
  dc.StretchBlt(dstRect.left,
                dstRect.top,
                dstRect.Width(),
                dstRect.Height(),
                &trsDC,
                 0,
                 0,
                 cxDIB,
                 cyDIB,
                 SRCCOPY);
   
     bmpDC.SelectObject(oldmBmp);
     memDC.SelectObject(oldtBmp);  
 
 It works well, the problem is too slow for transfer big bitmap especially on slow machine(such as 640*480 on 486). but it is really a way though I don't think it is not the best way.
 Hopy I can help you.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now