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. How to rotate an icon?

How to rotate an icon?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsbusinesstutorialquestion
19 Posts 5 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.
  • E Offline
    E Offline
    eli15021979
    wrote on last edited by
    #1

    Hi, I'm working on a project,and one of the requirements is to draw one of the icons in a different angle every time that the angle is updated. Is there any way to rotate the icon,or shall I use a bitmap instead of icon and blit the bitmap's pixels by myself(which can consume a lot of CPU?)? With best regards, Eli

    E L 2 Replies Last reply
    0
    • E eli15021979

      Hi, I'm working on a project,and one of the requirements is to draw one of the icons in a different angle every time that the angle is updated. Is there any way to rotate the icon,or shall I use a bitmap instead of icon and blit the bitmap's pixels by myself(which can consume a lot of CPU?)? With best regards, Eli

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      The better way is to have different[rotated,straight & all] icons/images in the resource and use them at the same place.. that would give you an "animated" effect rather than manipulating it at runtime.


      He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc. -Marc Clifton. Best wishes to Rexx[^

      E 1 Reply Last reply
      0
      • E Eytukan

        The better way is to have different[rotated,straight & all] icons/images in the resource and use them at the same place.. that would give you an "animated" effect rather than manipulating it at runtime.


        He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc. -Marc Clifton. Best wishes to Rexx[^

        E Offline
        E Offline
        eli15021979
        wrote on last edited by
        #3

        Hi VuNic, Thanks for your quick reply. My problem is that I need to rotate the icon is 360deg with resoultion of 0.5deg(i.e 720 icons...). I'm sure that there is a way to rotate an icon during runtime,but I can't find it...:doh: With best regards, Eli

        E M 2 Replies Last reply
        0
        • E eli15021979

          Hi VuNic, Thanks for your quick reply. My problem is that I need to rotate the icon is 360deg with resoultion of 0.5deg(i.e 720 icons...). I'm sure that there is a way to rotate an icon during runtime,but I can't find it...:doh: With best regards, Eli

          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #4

          0.5 degrees? :omg: Clickety[^] This might help you.


          He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc. -Marc Clifton. Best wishes to Rexx[^

          E 1 Reply Last reply
          0
          • E Eytukan

            0.5 degrees? :omg: Clickety[^] This might help you.


            He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc. -Marc Clifton. Best wishes to Rexx[^

            E Offline
            E Offline
            eli15021979
            wrote on last edited by
            #5

            Thanks again, I read this article(and others...),but the problem is that each one of those projects runs all over the pixels of the bitmap,which consume a lot of CPU... Thats why I thought the rotating an icon will be much more efective... Thanks anyway... Eli

            E M 2 Replies Last reply
            0
            • E eli15021979

              Thanks again, I read this article(and others...),but the problem is that each one of those projects runs all over the pixels of the bitmap,which consume a lot of CPU... Thats why I thought the rotating an icon will be much more efective... Thanks anyway... Eli

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #6

              Welcome, we'd wait for an image specialist here ;)


              He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc. -Marc Clifton. Best wishes to Rexx[^

              1 Reply Last reply
              0
              • E eli15021979

                Hi, I'm working on a project,and one of the requirements is to draw one of the icons in a different angle every time that the angle is updated. Is there any way to rotate the icon,or shall I use a bitmap instead of icon and blit the bitmap's pixels by myself(which can consume a lot of CPU?)? With best regards, Eli

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Hi, The code at codeguru: http://www.codeguru.com/Cpp/G-M/gdi/article.php/c3693/[^] optimizes quite nicely in VS2005. With speed optimization enabled, compiler intrinsics, and /ARCH:SSE the VS2005 compiler does a pretty damn good job at optimizing his code. Download the sample and give it a shot. 0 to 1% cpu usage on my laptop even when I set the timer to 1ms (of which the smallest quantum is around 10ms) Hope it helps, -Randor (David Delaune)

                L 1 Reply Last reply
                0
                • L Lost User

                  Hi, The code at codeguru: http://www.codeguru.com/Cpp/G-M/gdi/article.php/c3693/[^] optimizes quite nicely in VS2005. With speed optimization enabled, compiler intrinsics, and /ARCH:SSE the VS2005 compiler does a pretty damn good job at optimizing his code. Download the sample and give it a shot. 0 to 1% cpu usage on my laptop even when I set the timer to 1ms (of which the smallest quantum is around 10ms) Hope it helps, -Randor (David Delaune)

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Btw: You can modify the project properties at 'Output Files' and enable 'Assembler Output' as 'Assembly with Source Code /FAs' Check out the beautiful asm code optimizations... MMX and SSE very nicely optimized by the compiler, I have been impressed with the optimizations of VS2005. I have nearly always been able to manually generate asm code by hand to outperform visual studio. This is the first compiler I have a hard time beating! Cant' wait to see VS2008 'Orcas' optimizer. -Randor (David Delaune)

                  G 1 Reply Last reply
                  0
                  • E eli15021979

                    Thanks again, I read this article(and others...),but the problem is that each one of those projects runs all over the pixels of the bitmap,which consume a lot of CPU... Thats why I thought the rotating an icon will be much more efective... Thanks anyway... Eli

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

                    How big is the icon? GDI+ would make it simple to code. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    1 Reply Last reply
                    0
                    • E eli15021979

                      Hi VuNic, Thanks for your quick reply. My problem is that I need to rotate the icon is 360deg with resoultion of 0.5deg(i.e 720 icons...). I'm sure that there is a way to rotate an icon during runtime,but I can't find it...:doh: With best regards, Eli

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

                      eli15021979 wrote:

                      0.5deg(i.e 720 icons...)

                      What is "720 icons"? Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      E 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        eli15021979 wrote:

                        0.5deg(i.e 720 icons...)

                        What is "720 icons"? Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        E Offline
                        E Offline
                        eli15021979
                        wrote on last edited by
                        #11

                        Hi Mark,

                        Mark Salsbery wrote:

                        What is "720 icons"?

                        VuNic wrote:

                        The better way is to have different[rotated,straight & all] icons/images in the resource and use them at the same place.. that would give you an "animated" effect rather than manipulating it at runtime.

                        I need to be able rotate the icon 360 degrres , with resolution of 0.5 degrees , so if I want to use Vunic's way , I need total of 720 icons (2 icons per 1 degree...). I'm preety sure that there is a way to rotate the displayed icon,but still,I can't find any article or post in the forum for the related issue... Maybe you can help me??? With best regards, Eli

                        L M 2 Replies Last reply
                        0
                        • E eli15021979

                          Hi Mark,

                          Mark Salsbery wrote:

                          What is "720 icons"?

                          VuNic wrote:

                          The better way is to have different[rotated,straight & all] icons/images in the resource and use them at the same place.. that would give you an "animated" effect rather than manipulating it at runtime.

                          I need to be able rotate the icon 360 degrres , with resolution of 0.5 degrees , so if I want to use Vunic's way , I need total of 720 icons (2 icons per 1 degree...). I'm preety sure that there is a way to rotate the displayed icon,but still,I can't find any article or post in the forum for the related issue... Maybe you can help me??? With best regards, Eli

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Whats wrong with the link to the code I posted earlier? -Randor (David Delaune)

                          E 1 Reply Last reply
                          0
                          • L Lost User

                            Whats wrong with the link to the code I posted earlier? -Randor (David Delaune)

                            E Offline
                            E Offline
                            eli15021979
                            wrote on last edited by
                            #13

                            Hi David, I just finished reading this article,and it seems preety good. I will give it a try... But still,isn't any way to rotate an icon? Thanks anyway for your quick and helpful reply. With best regards, Eli

                            L 1 Reply Last reply
                            0
                            • E eli15021979

                              Hi Mark,

                              Mark Salsbery wrote:

                              What is "720 icons"?

                              VuNic wrote:

                              The better way is to have different[rotated,straight & all] icons/images in the resource and use them at the same place.. that would give you an "animated" effect rather than manipulating it at runtime.

                              I need to be able rotate the icon 360 degrres , with resolution of 0.5 degrees , so if I want to use Vunic's way , I need total of 720 icons (2 icons per 1 degree...). I'm preety sure that there is a way to rotate the displayed icon,but still,I can't find any article or post in the forum for the related issue... Maybe you can help me??? With best regards, Eli

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

                              eli15021979 wrote:

                              I need total of 720 icons (2 icons per 1 degree...).

                              Ohhh, I got it LOL :) What is the icon's dimensions and how often (per-second) does it get rotated? GDI+ will do it for you with minimal code. If the icon is the size of the screen and you rotate it 60 times per second then it may not be the most efficient method :) Randor's link shows a way to do it manually as well. Mark

                              Mark Salsbery Microsoft MVP - Visual C++ :java:

                              E 1 Reply Last reply
                              0
                              • M Mark Salsbery

                                eli15021979 wrote:

                                I need total of 720 icons (2 icons per 1 degree...).

                                Ohhh, I got it LOL :) What is the icon's dimensions and how often (per-second) does it get rotated? GDI+ will do it for you with minimal code. If the icon is the size of the screen and you rotate it 60 times per second then it may not be the most efficient method :) Randor's link shows a way to do it manually as well. Mark

                                Mark Salsbery Microsoft MVP - Visual C++ :java:

                                E Offline
                                E Offline
                                eli15021979
                                wrote on last edited by
                                #15

                                Hi again,

                                Mark Salsbery wrote:

                                What is the icon's dimensions and how often (per-second) does it get rotated?

                                Icon's size is 32X32 or 64X64. Refressh rate is 4Hz(every 250msec). I read the article from Randor's link and it seems to work, But I think that rotating the icons instead of drawing bitmaps is more efficient...(I'm sure that the people from MS can do the work better than me.....or not?;P). I'm not familiar with GDI+(only GDI),but it is always good to learn something new... Thanks,again... With best regards, Eli

                                M 1 Reply Last reply
                                0
                                • E eli15021979

                                  Hi David, I just finished reading this article,and it seems preety good. I will give it a try... But still,isn't any way to rotate an icon? Thanks anyway for your quick and helpful reply. With best regards, Eli

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #16

                                  Hi, The link I posted is a very fast way to rotate a bitmap using the memory directly on the DIB. I think maybe you have a misunderstanding of what an ICON is. A icon is simply a bitmap... an array of bytes in memory. Its not a vector format such as SVG or a mathematical model of a shape such as flash. Vector image formats can be rotated extremely fast, however an ICON is not a vector. More on vector graphics: http://en.wikipedia.org/wiki/Vector_graphics[^] An ICON is a raster format... as previous stated, this is an array of bytes. More about raster formats: http://en.wikipedia.org/wiki/Raster_graphics[^] In essense what I am saying is that if you want to rotate a bitmap, there is no other way but to rotate all of the bytes representing the image. The question then becomes... 'How fast can I rotate all of those bytes in the multidimensional array'. The answer is multimedia instructions such as MMX and SSE/SSE2/SSSE which allow you to manipulate multiple bytes in a single instruction. This is why I was pointing out in my previous post how well the code from Yves Maurer at codeguru was bei ng optimized. I was attempting to illustrate that the performance was very good. In laymen terms, what I am saying is: 1.)A standard beginner level algorithm for rotating a 32x32 icon would be to move each and every pixel one at a time. 32 loops of 32 pixel movements. 2.) Utilizing multimedia instructions such as MMX/SSE/SSE2/SSSE you can manipulate multiple pixels at once. For example... instead of 32 iterations of 32 pixel movements; You may be able to optimize it to 32 iterations of 4/8 movements, depening on multimedia optimizations. In the old days we had to do much of the asm code ourselves, however beginning with VS2005 many of us asm programmers began seeing that the Visual studio optimizer was doing a hell of a good job. The code implemented by Yves Maurer can optimize very well, I would recommend using it for your bitmap rotation. Yes there may be slightly more efficient implementations somewhere out on the web, but the margin of gain will be small. -Randor (David Delaune)

                                  E 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Hi, The link I posted is a very fast way to rotate a bitmap using the memory directly on the DIB. I think maybe you have a misunderstanding of what an ICON is. A icon is simply a bitmap... an array of bytes in memory. Its not a vector format such as SVG or a mathematical model of a shape such as flash. Vector image formats can be rotated extremely fast, however an ICON is not a vector. More on vector graphics: http://en.wikipedia.org/wiki/Vector_graphics[^] An ICON is a raster format... as previous stated, this is an array of bytes. More about raster formats: http://en.wikipedia.org/wiki/Raster_graphics[^] In essense what I am saying is that if you want to rotate a bitmap, there is no other way but to rotate all of the bytes representing the image. The question then becomes... 'How fast can I rotate all of those bytes in the multidimensional array'. The answer is multimedia instructions such as MMX and SSE/SSE2/SSSE which allow you to manipulate multiple bytes in a single instruction. This is why I was pointing out in my previous post how well the code from Yves Maurer at codeguru was bei ng optimized. I was attempting to illustrate that the performance was very good. In laymen terms, what I am saying is: 1.)A standard beginner level algorithm for rotating a 32x32 icon would be to move each and every pixel one at a time. 32 loops of 32 pixel movements. 2.) Utilizing multimedia instructions such as MMX/SSE/SSE2/SSSE you can manipulate multiple pixels at once. For example... instead of 32 iterations of 32 pixel movements; You may be able to optimize it to 32 iterations of 4/8 movements, depening on multimedia optimizations. In the old days we had to do much of the asm code ourselves, however beginning with VS2005 many of us asm programmers began seeing that the Visual studio optimizer was doing a hell of a good job. The code implemented by Yves Maurer can optimize very well, I would recommend using it for your bitmap rotation. Yes there may be slightly more efficient implementations somewhere out on the web, but the margin of gain will be small. -Randor (David Delaune)

                                    E Offline
                                    E Offline
                                    eli15021979
                                    wrote on last edited by
                                    #17

                                    Hi David, WOW - this is all I have to say...(and thanks also...:-O). All I wanted is to know if there is an API which do the rotation, but from the code you gave me through your post,and with your [detailed] explanation, I think I can solve my problem. Thanks again, and keep the good work by helping others. With best regards, Eli

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      Btw: You can modify the project properties at 'Output Files' and enable 'Assembler Output' as 'Assembly with Source Code /FAs' Check out the beautiful asm code optimizations... MMX and SSE very nicely optimized by the compiler, I have been impressed with the optimizations of VS2005. I have nearly always been able to manually generate asm code by hand to outperform visual studio. This is the first compiler I have a hard time beating! Cant' wait to see VS2008 'Orcas' optimizer. -Randor (David Delaune)

                                      G Offline
                                      G Offline
                                      GepardHH
                                      wrote on last edited by
                                      #18

                                      Hi, you can mix the solutions. first load the original icon as bitmap and rotate it 720 times, store the bitmaps as 720 icons ( use CreateIcon() ), than use the stored icons. You need to do the computation only once at program start and avoid the administration overhead of having 720 icons in the resource file. :) Regards, Georg

                                      Regards, Georg

                                      1 Reply Last reply
                                      0
                                      • E eli15021979

                                        Hi again,

                                        Mark Salsbery wrote:

                                        What is the icon's dimensions and how often (per-second) does it get rotated?

                                        Icon's size is 32X32 or 64X64. Refressh rate is 4Hz(every 250msec). I read the article from Randor's link and it seems to work, But I think that rotating the icons instead of drawing bitmaps is more efficient...(I'm sure that the people from MS can do the work better than me.....or not?;P). I'm not familiar with GDI+(only GDI),but it is always good to learn something new... Thanks,again... With best regards, Eli

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

                                        You probably have your solution by now, but just to provide another option, here's GDI+ code that rotates an icon (in a window) around its center point, 360 degrees at 0.5 degree intervals:

                                        // Note - this assumes icon is 96x96 - use the appropriate dimensions when loading the icon with LoadImage()

                                        HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI\_MYICON), IMAGE\_ICON, 96, 96, 0);
                                        

                                        Gdiplus::Bitmap SrcBitmap(hIcon);

                                        Graphics DstGraphics(*this); // "*this" is the destination HWND
                                            REAL angle = 0.0f;
                                            for (int i = 0; i < 720; ++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 += 0.5f;
                                            }

                                        Mark

                                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                                        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