Results 1 to 6 of 6

Thread: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Question How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    I have drawn a bitmap image using GDI+ in C# on a windows form and would like to rotate the image while the up arrow key is pressed.

    The effect I would like to get is to see the image move in a circular motion while it rotates. The rotation angle is incremented by 5 degrees each time the key pressed event handler executes.

    The problem is that while the image does move in a circular path, a string of previously rotated images appear along the rotation path instead of just the latest rotated image.

    i.e. If the maximum angle is set to 20 degrees, 4 images will be on the screen with the first rotated at 5 degrees, the next at 10 degrees and so on.

    How do I just show a single bitmap image rotating instead of a string of previous images showing up along the rotation path?

    The code is shown below:

    Code:
    (in the form1 load event)
    Graphics g = CreateGraphics();            
    granade = new Bitmap("granade.jpg");
    
    (in the form1 paint event) 
    g.DrawImage(granade,0,0,20,20);
    
    (in the key down event)
    Matrix rotMatrix = new Matrix();
    rotateAngle -= 5;
    
    rotMatrix.RotateAt(rotateAngle);
    g.Transform = rotMatrix;

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    Clear the screen before each new rotation. By "Clear" I mean paint whatever background you want first before painting the rotated image. The background could be anything from another bitmap or simply just a white area. You've failed to give us a screenshot of your problem. Please upload a screenshot.
    I don't live here any more.

  3. #3
    Junior Member MushroomSamba's Avatar
    Join Date
    Sep 2008
    Location
    In my room.
    Posts
    19

    Re: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    Quote Originally Posted by wossname
    You've failed to give us a screenshot of your problem. Please upload a screenshot.
    Is a screenshot really necessary? His question was pretty clear and you hit the nail on the head as far as answering it.

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Location
    United Kingdom
    Posts
    18

    Re: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    Or if you are looking for speed, rather than clear the screen, draw a blank line(s) along the trailing edge to clear

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Re: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    Is it to create a new window sized bitmap for copying and clearing for each frame?

    Is there an alternative method to this as the window already has 2 bitmaps, one of which is a 2D terrain which is generated by an algorithm. Having to regenerate the terrain for each frame is too slow. Drawing lines would also not work in this case due to the background bitmap i guess?

    I noticed that there is something like a "copy from background" method where pixels from the background are copied onto the bitmap. Could this method work where for each frame, the background overwrites the previous bitmap?


  6. #6
    Junior Member
    Join Date
    Sep 2008
    Location
    United Kingdom
    Posts
    18

    Re: How to rotate a bitmap image cleanly in GDI+ without a string of images appearing?

    Could you not generate the terrain to bmp in memory, copy this render over the copy and then copy to screen .... sounds like a lot of work, but working in memory ... not having to re render you background could be quicker(er)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width