Results 1 to 3 of 3

Thread: rotating an images, no rotateflip

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    rotating an images, no rotateflip

    hi,
    I need to rotate a picture box with about 35 degrees. now I tried this

    Code:
    PictureBox1.CreateGraphics.ResetTransform()
                PictureBox1.CreateGraphics.TranslateTransform(64.0F, 64.0F)
                PictureBox1.CreateGraphics.RotateTransform(35) 
    
                PictureBox1.CreateGraphics.DrawImage(sword, (-sword.Width \ 2), -sword.Height \ 2)
    
                PictureBox1.Refresh()
    But it doesn't seem to work Does someone know how to do this

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: rotating an images, no rotateflip

    Don't use CreateGraphics for drawing in dotNet. Instead use the graphics in the Paint event sub:

    Code:
    Private Sub Picture_Box1.Paint(sender As Object, e As PaintEventArgs) _
          _Handles PictureBox1.Paint
         'no need for ResetTransform
         e.Graphics.TranslateTransform(64.0F, 64.0F)
         e.Graphics.RotateTransform(35)
         e.Graphics.DrawImage(... etc.)
         'DO NOT put Refresh here!!!
    End Sub
    When you need to make the Paint event fire, put PictureBox1.Refresh or PictureBox1.Invalidate in another sub -- for example a ButtonClick, Timer.Tick or MouseMove depending on what you are doing.

    BB


    Then you can be sure that Windows can repaint the rotated image whenever necessary.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    Re: rotating an images, no rotateflip

    It rotates 35 degrees, but it is out of focus.
    Last edited by ikdekker; Jan 29th, 2012 at 01:57 PM.

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