Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Rotating Bitmaps !!!!

Rotating Bitmaps !!!!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adno
    wrote on last edited by
    #1

    Im using this method needless to say is not working and need some help. void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays } Thank you

    R M 2 Replies Last reply
    0
    • A Adno

      Im using this method needless to say is not working and need some help. void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays } Thank you

      R Offline
      R Offline
      rrrado
      wrote on last edited by
      #2

      what does it display? Try to set some pixels in destination bmp with some constatnt color to check if there is problem in rotation alghoritm or displaying


      rrrado

      1 Reply Last reply
      0
      • A Adno

        Im using this method needless to say is not working and need some help. void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays } Thank you

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Also, if you aren't required to write the rotation code yourself, GDI+ will do it for you :) Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        A 1 Reply Last reply
        0
        • M Mark Salsbery

          Also, if you aren't required to write the rotation code yourself, GDI+ will do it for you :) Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          A Offline
          A Offline
          Adno
          wrote on last edited by
          #4

          hi the GDI+ i find is not very precise Mark i mean the image center shifts, and you have to draw the image then rotate the DC then draw it again you end up with two images and a rotated DC lol the method i posted is skipping the second for loop for some reason :wtf: thanks for your replies... back to digging :)

          M 1 Reply Last reply
          0
          • A Adno

            hi the GDI+ i find is not very precise Mark i mean the image center shifts, and you have to draw the image then rotate the DC then draw it again you end up with two images and a rotated DC lol the method i posted is skipping the second for loop for some reason :wtf: thanks for your replies... back to digging :)

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            hmm I've found it to be precise. Controlling the image center is easy handled. I'm not sure what you mean by rotating a DC and ending up with two images - It uses pretty much the same technique you are using. Check this out (if you want to :)). This spins an image (in a window, so you can watch) around its center point (like a propellor LOL) at 5 degree increments...

            Gdiplus::Bitmap SrcBitmap(L"C:\\test.bmp", FALSE);

            Graphics DstGraphics(*this); // use an appropriate HWND here

            REAL angle = 0.0f;
            for (int i = 0; i < 200; ++i)
            {
            DstGraphics.ResetTransform();
            DstGraphics.RotateTransform(angle);
            DstGraphics.TranslateTransform(SrcBitmap.GetWidth() / 2.0f, SrcBitmap.GetWidth() / 2.0f, MatrixOrderAppend);
            DstGraphics.DrawImage(&SrcBitmap, -((INT)SrcBitmap.GetWidth() / 2), -((INT)SrcBitmap.GetHeight() / 2),
            SrcBitmap.GetWidth(), SrcBitmap.GetHeight());

            angle += 5.0f;
            if (angle >= 360.0f)
            angle -= 360.0f;

            //::Sleep(70);
            }

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            A 1 Reply Last reply
            0
            • M Mark Salsbery

              hmm I've found it to be precise. Controlling the image center is easy handled. I'm not sure what you mean by rotating a DC and ending up with two images - It uses pretty much the same technique you are using. Check this out (if you want to :)). This spins an image (in a window, so you can watch) around its center point (like a propellor LOL) at 5 degree increments...

              Gdiplus::Bitmap SrcBitmap(L"C:\\test.bmp", FALSE);

              Graphics DstGraphics(*this); // use an appropriate HWND here

              REAL angle = 0.0f;
              for (int i = 0; i < 200; ++i)
              {
              DstGraphics.ResetTransform();
              DstGraphics.RotateTransform(angle);
              DstGraphics.TranslateTransform(SrcBitmap.GetWidth() / 2.0f, SrcBitmap.GetWidth() / 2.0f, MatrixOrderAppend);
              DstGraphics.DrawImage(&SrcBitmap, -((INT)SrcBitmap.GetWidth() / 2), -((INT)SrcBitmap.GetHeight() / 2),
              SrcBitmap.GetWidth(), SrcBitmap.GetHeight());

              angle += 5.0f;
              if (angle >= 360.0f)
              angle -= 360.0f;

              //::Sleep(70);
              }

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              A Offline
              A Offline
              Adno
              wrote on last edited by
              #6

              :-D:-D:-D:-D:-D:-D:-D:-D

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups