Results 1 to 5 of 5

Thread: Rotate image of windbarb around tip point

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Rotate image of windbarb around tip point

    Hello all,
    I have a collection of windbarbs of different wind velocities that i need to have displayed on a map. I would like the image to use the bottom of the windbarb/tip ad the rotation point. This is needed because the windbarb is oriented in which the wind is coming from. Below is the routine i am using. The size of the windbarb image is 12px wide X 57px height.

    Code:
     Private Function RotateImage(image As Image, angle As Single) As Bitmap
            ' the calling code is responsible for (and must) 
            ' disposing of the bitmap returned
    
            Dim retBMP As New Bitmap(image)
            retBMP.SetResolution(image.HorizontalResolution, image.VerticalResolution)
    
            Using g = Graphics.FromImage(retBMP)
                g.TranslateTransform(CSng(image.Width / 2), CSng(image.Height / 2))
                g.RotateTransform(angle)
                g.DrawImage(retBMP, New Point(-image.Width \ 2, -image.Height \ 2))
            End Using
    
            Return retBMP
    
        End Function
    Last edited by jwyman; Aug 9th, 2022 at 07:25 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Rotate image of windbarb around tip point

    Ok. First, always format code when you post it in this forum

    [code]’ your code[/code]

    Will format as…

    Code:
    ’ your code
    Secondly, you’ve posted code, and a brief description of your intentions, but you haven’t told us whether your code works, or what doesn’t work about it???

    If you want to rotate around a point, you’d generally use [graphics].TranslateTransForm(x, y), before the rotate call…

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Re: Rotate image of windbarb around tip point

    It appears that the image is rotating around the center of the image defined coordinates.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Re: Rotate image of windbarb around tip point

    I have attached an image of the map with the windbarb displayed. I need to have this image rotate around from 0-360 degrees with the pivot point being the base of the windbarb.

    Attachment 185481

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2022
    Posts
    4

    Re: Rotate image of windbarb around tip point

    Solution Found!

    Code:
      Try
    
                Dim MaxSize As Integer
    
                Dim retBMP As New Bitmap(image)
    
                MaxSize = Math.Max(image.Width, image.Height) * 2
    
                Dim tempImage As New Bitmap(MaxSize, MaxSize)
    
                retBMP.SetResolution(image.HorizontalResolution, image.VerticalResolution)
    
                Using g = Graphics.FromImage(tempImage)
    
                    g.TranslateTransform(CSng(tempImage.Width / 2), CSng(tempImage.Height / 2))
    
                    g.RotateTransform(angle)
    
                    g.DrawImage(retBMP, New PointF(0, -image.Height))
    
                    g.ResetTransform()
    
                    Return tempImage
    
                End Using
    
    
    
            Catch ex As Exception
                MsgBox(ex.Message & vbCrLf & ex.StackTrace)
            End Try

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