Rotate An Image in Visual
Rotate An Image in Visual
html
GLP NMR Services Selcia perform GLP compliant PI NMR studies www.selcia.com
Mobile App UI & UX Design We create usable and stylish user interfaces for iOS, Android and WM innovationbox.com
Douglas Labs 25% Off Great Discounts on Douglas Labs 25% off. www.vnfnutrition.com
Search - Articles
FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with
Windows Server Purchase
Home
Dev Articles How to rotate an image in Visual Basic.Net
Sample Chapters Visual FoxPro 10
Add a Listing Author: DevASP Cross platform Visual
Contact Download Source Code : 391_Rotate Image.zip FoxPro for
Windows/OS X/Linux
This article is about how you can rotate an image at your desire angle. In this article we will use the system.math namespace to /Cloud/Mobile
Dev Articles www.lianja.com
rotate image on desired angle.
ASP.NET (502)
C# (300) Diindolylmethane
SQL Server (59) Image resizing on the fly www.aspjpeg.com Dietary ingredient
Make high-quality image thumbnails with this raw material ETI -
VB.NET (195)
ASP/ASP.NET component.
Web Services (6) bulk and laboratory
sales
www.etichem.com
Search Directory Get a Better BASIC www.powerbasic.com
Multi-Core Coding at a better price A professional
compiler @ $49 Word Processor
ASP.Net AJAX
AJAX ToolKit
Control
.NET Namespaces Use Word as control
10% OFF Radiochemicals www.arcincusa.com in Net, ASP.Net Java
Applications American Radiolabeled Chemicals High quality 14C,
without local
Articles & Samples 3H, 125I, 35S
Assembly & installation
www.pintexx.com
Controls
Community Customized Mobile Modules www.acktie.com/
Developer Sites Rapidly develop mobile apps by piecing our clean Package Design
Downloads modules together!
Integrated Design &
Hosting Services Prepress Accelerate
Introduction Speed to Market
Knowledge Base Steps you will do. www.sgsintl.com
Sample Chapters Start visual studio and create a new window application.
WebCasts Drop a text field on the form and set its following properties.
Visual Basic
ASP.NET Programming
Free Help &
Text = “30” Discussion with VB
Applications Name = “txtAngle”
Articles & Samples Pros & Experts.
ASP.Net Sites Register Today!
www.daniweb.com
Assembly & Drop a button control on the form and set its following properties .
Controls
Downloads
Errors & Bugs
Introduction Name = “btnRotate”
Knowledge Base Text = “Rotate”
Sample Chapters
WebCasts
Drop two picture box control on the form and set their properties as below.
VB.Net
Applications
Articles & Samples
C-Sharp Sites Drop a label control on the form and set its following properties.
Errors, Bugs &
Fixes
Introduction
Text = “Angle”
Knowledge Base
Sample Chapters
WebCasts
Open your code window and import system.math namespace as below.
SQL Server
1 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual Basic.Net - .Net Articles & Samples http://www.devasp.net/net/articles/display/391.html
Dim i As Long
For i = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i
Dim X As Single
Dim Y As Single
For i = 0 To 3
X = corners(i).X
Y = corners(i).Y
Next i
For i = 1 To 3
Next i
For i = 0 To 3
corners(i).X -= xmin
corners(i).Y -= ymin
Next i
gr_out.DrawImage(bm_in, corners)
picDest.Image = bm_out
Article Comments
Yocheved Hello,
2 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual Basic.Net - .Net Articles & Samples http://www.devasp.net/net/articles/display/391.html
I need help about rotate an image in vb.net. I tested a piece of code was posted in this forum, but, it
works well only in the first time. I saved the rezult of the first time in a bitmap and then I run this operation
again and again. Any time I run it again, the rezult picture was been bigger and bigger while the orginal
picture was in a same size, but the background was be bigger and bigger.
Can any help me?
I send below the code I used to rotate the bitmap. In the beggining of the code I get the width and the
height of the bitmap. If you will run this code again and again You will see that the width and the height of
the bitmap will be bigger and bigger.
Thanks,
Yocheved
bm_in was initted in the load event on the form like this:
dim bm_in as bitmap = new bitmap("d:\temp\pic1.jpg")
after it I run the code below on bm_in again and again.
' Rotate.
Dim theta As Single = Single.Parse(30) * Math.PI _
/ 180.0
Dim sin_theta As Single = Math.Sin(theta)
Dim cos_theta As Single = Math.Cos(theta)
Dim X As Single
Dim Y As Single
For i = 0 To 3
X = corners(i).X
Y = corners(i).Y
corners(i).X = X * cos_theta + Y * sin_theta
corners(i).Y = -X * sin_theta + Y * cos_theta
Next i
curseddagger Fantastic, finally i found what i have been looking for, thanks heaps!
Been trying to find an answer for awhile. Your code is the closest. Only issue is I am working with the
.net compact frameworks and it won't accet the following code:
"gr_out.DrawImage(bm_in, corners)"
3 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual Basic.Net - .Net Articles & Samples http://www.devasp.net/net/articles/display/391.html
Error reads, "Overload resolution failed because no accessible 'DrawImage' accepts this number of
arguments."
This happens only with the .net compact framework and smart device apps. Please help.
Thanks.
L0wger I was looking for something like this. Thank you so much
naderenator excellent
rockwell To Yocheved:
If you rotate a bitmap the picture has to become bigger. You cant rotate a square inside another square
of the same size, so the outer square (the bounds of your image) have to enlarge to accompany the
change of the inner square (the image itself).
If you rotate a square clockwise, for example, the top left corner raises up, the bottom left corner move
farther left, the bottom right corner moves down, and the top right corner moves right. Since a bitmap is
saved only as a square that its edges face vertical and horizontal, it compensates and increases the
image size every time you rotate (unless its a perfect square and your rotation is in increments of 90
degrees)
Dim X As Single = 30
Dim Y As Single = 50
4 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual Basic.Net - .Net Articles & Samples http://www.devasp.net/net/articles/display/391.html
string_format.Alignment = StringAlignment.Center
string_format.LineAlignment = StringAlignment.Center
G.RotateTransform(Angle, MatrixOrder.Append)
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
G.Restore(InitialState)
Dalia To Youssof
your method rotates a text not an image
but it is very interesting too!
ekalo Hi there,
I need same rotating from video (mediaplayer or another player), can we do?
Thnx.
Comments :
Send me an email about this article when other users post a Comment
5 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual Basic.Net - .Net Articles & Samples http://www.devasp.net/net/articles/display/391.html
Serializing & Deserializing Objects Using Standard and Binary Formatter in VB.Net >>
Disclaimer - Privacy
© 2002-2012 DevASP.net
6 of 6 13/07/2012 11:54 AM