  Advertiser Disclosure
 TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow    Language: VB7
Expertise: Intermediate
Nov 18, 2002

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

# DrawRotateImage - rotating an image by a specified angle

``````' Rotate an image by a specified angle (in degrees)
' The x and y parameters are the coordinates of the upper-left point
' Note: requires Imports System.Drawing.Imaging
'
' Example:
'   Dim gr As Graphics = Me.CreateGraphics
'   gr.Clear(Color.White)
'   Dim bmp As New Bitmap("logo.bmp")
'   DrawRotateImage(gr, bmp, 100, 220, 45)
'   DrawRotateImage(gr, bmp, 300, 220, 90)
'   DrawRotateImage(gr, bmp, 500, 220, 135)
'   bmp.Dispose()
'   gr.Dispose()

Sub DrawRotateImage(ByVal gr As Graphics, ByVal bmp As Bitmap, _
ByVal x As Single, ByVal y As Single, ByVal angle As Single)
' Convert the angle in degrees.
angle = angle / (180 / Math.PI)
' Find the position of (x1,y1) and (x2,y2).
Dim x1 As Single = x + bmp.Width * Math.Cos(angle)
Dim y1 As Single = y + bmp.Width * Math.Sin(angle)
Dim x2 As Single = x - bmp.Height * Math.Sin(angle)
Dim y2 As Single = y + bmp.Height * Math.Cos(angle)

' Create the points array.
Dim points() As Point = {New Point(x, y), New Point(x1, y1), New Point(x2, _
y2)}
' Draw the rotated image
gr.DrawImage(bmp, points)
End Sub

' Note: This code is taken from Francesco Balena's
' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753
' You can read a free chapter of the book at
' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000``````
Francesco Balena Submit a Tip Browse "Application Design" Tips Browse All Tips   Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.    Thanks for your registration, follow us on our social networks to keep up-to-date