-
Aug 8th, 2022, 05:45 PM
#1
Thread Starter
New Member
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.
-
Aug 8th, 2022, 08:16 PM
#2
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…
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…
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 8th, 2022, 08:35 PM
#3
Thread Starter
New Member
Re: Rotate image of windbarb around tip point
It appears that the image is rotating around the center of the image defined coordinates.
-
Aug 9th, 2022, 10:57 AM
#4
Thread Starter
New Member
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
-
Aug 9th, 2022, 12:54 PM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|