0% found this document useful (0 votes)
80 views6 pages

Rotate An Image in Visual

rotate an image in Visual Basic

Uploaded by

aung aung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views6 pages

Rotate An Image in Visual

rotate an image in Visual Basic

Uploaded by

aung aung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

How to rotate an image in Visual [Link] - .Net Articles & Samples [Link]

html

GLP NMR Services Selcia perform GLP compliant PI NMR studies [Link]

Mobile App UI & UX Design We create usable and stylish user interfaces for iOS, Android and WM [Link]

Douglas Labs 25% Off Great Discounts on Douglas Labs 25% off. [Link]

Search - Articles

FREE 12 month online training for [Link] & 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 [Link]
Sample Chapters Visual FoxPro 10
Add a Listing Author: DevASP Cross platform Visual
Contact Download Source Code : 391_Rotate [Link] 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 [Link] namespace to /Cloud/Mobile
Dev Articles [Link]
rotate image on desired angle.
[Link] (502)
C# (300) Diindolylmethane
SQL Server (59) Image resizing on the fly [Link] Dietary ingredient
Make high-quality image thumbnails with this raw material ETI -
[Link] (195)
ASP/[Link] component.
Web Services (6) bulk and laboratory
sales
[Link]
Search Directory Get a Better BASIC [Link]
Multi-Core Coding at a better price A professional
compiler @ $49 Word Processor
[Link] AJAX
AJAX ToolKit
Control
.NET Namespaces Use Word as control
10% OFF Radiochemicals [Link] in Net, [Link] Java
Applications American Radiolabeled Chemicals High quality 14C,
without local
Articles & Samples 3H, 125I, 35S
Assembly & installation
[Link]
Controls
Community Customized Mobile Modules [Link]/
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. [Link]
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
[Link] Programming
Free Help &
Text = “30” Discussion with VB
Applications Name = “txtAngle”
Articles & Samples Pros & Experts.
[Link] Sites Register Today!
[Link]
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.

[Link]

Articles & Samples


First picture box.
Name = “picSource”
Downloads
Image = “Browse and give any image”
Errors, Bugs &
Modifiers = “Friend”
Fixes
Sizemode = “Autosize”
Introduction
Knowledge Base
Sample Chapters
Second picture box.
WebCasts Name = “picDest”
Modifiers = “Friend”
C-Sharp Sizemode = “Autosize”

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 [Link] namespace as below.
SQL Server

Applications Imports [Link]


Articles & Samples
SQL Sites
Downloads
Errors, Bugs &
Fixes Now in the click event of the button write following code to rotate the image at your desire angle.
Introduction
Knowledge Base
Sample Chapters
WebCasts

1 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual [Link] - .Net Articles & Samples [Link]

Dim bm_in As New Bitmap([Link])

Dim wid As Single = bm_in.Width

Dim hgt As Single = bm_in.Height

Dim corners As Point() = { _

New Point(0, 0), _

New Point(wid, 0), _

New Point(0, hgt), _

New Point(wid, hgt)}

Dim cx As Single = wid / 2

Dim cy As Single = hgt / 2

Dim i As Long

For i = 0 To 3

corners(i).X -= cx

corners(i).Y -= cy

Next i

Dim theta As Single = [Link]([Link]) * PI / 180.0

Dim sin_theta As Single = Sin(theta)

Dim cos_theta As Single = 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

Dim xmin As Single = corners(0).X

Dim ymin As Single = corners(0).Y

For i = 1 To 3

If xmin > corners(i).X Then xmin = corners(i).X

If ymin > corners(i).Y Then ymin = corners(i).Y

Next i

For i = 0 To 3

corners(i).X -= xmin

corners(i).Y -= ymin

Next i

Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin))

Dim gr_out As Graphics = [Link](bm_out)

ReDim Preserve corners(2)

gr_out.DrawImage(bm_in, corners)

[Link] = bm_out

Article Comments

MuthuKumar It's good

Posted on 7/25/2006 [Link] AM by MuthuKumar

Yocheved Hello,

2 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual [Link] - .Net Articles & Samples [Link]

I need help about rotate an image in [Link]. 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\[Link]")
after it I run the code below on bm_in again and again.

' Make an array of points defining the


' image's corners.
Dim wid As Single = bm_in.Width
Dim hgt As Single = bm_in.Height
Dim corners As Point() = { _
New Point(0, 0), _
New Point(wid, 0), _
New Point(0, hgt), _
New Point(wid, hgt)}

' Translate to center the bounding box at the origin.


Dim cx As Single = wid / 2
Dim cy As Single = hgt / 2
Dim i As Long
For i = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i

' Rotate.
Dim theta As Single = [Link](30) * [Link] _
/ 180.0
Dim sin_theta As Single = [Link](theta)
Dim cos_theta As Single = [Link](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

' Translate so X >= 0 and Y >=0 for all corners.


Di

Posted on 3/12/2007 [Link] AM by Yocheved

curseddagger Fantastic, finally i found what i have been looking for, thanks heaps!

Posted on 3/19/2007 [Link] PM by curseddagger

Colin Ong Thanks for the code, it is great

Posted on 5/3/2007 [Link] AM by Colin Ong

Noob1000 Well done!Thank you for this informations.

Posted on 5/7/2007 [Link] AM by Noob1000

Ronald Wells Question.

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 [Link] - .Net Articles & Samples [Link]

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.

Posted on 9/13/2007 [Link] PM by Ronald Wells

L0wger I was looking for something like this. Thank you so much

Posted on 11/17/2007 [Link] PM by L0wger

ShipsBridge Works precisely how I wanted it to! Thanks!

Posted on 1/2/2008 [Link] PM by ShipsBridge

uma wow, thats excellent code, keep it up

Posted on 1/20/2008 [Link] PM by uma

Pete This is excellent - works a treat!

Posted on 9/2/2008 [Link] AM by Pete

Ram how to rotate the image in [Link] with C#

Posted on 3/21/2010 [Link] AM by Ram

naderenator excellent

Posted on 5/27/2010 [Link] PM by naderenator

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)

Posted on 6/28/2010 [Link] PM by rockwell

Youssof Dim Word As String = "Youssof"


Dim FontType As String = "Arial"
Dim FontSize As Integer = 12
Dim Angle As Integer = 90
Dim G As Graphics = [Link]

Dim X As Single = 30
Dim Y As Single = 50

Dim WordDimention As [Link] = [Link](Word, New Font(FontType, FontSize))

4 of 6 13/07/2012 11:54 AM
How to rotate an image in Visual [Link] - .Net Articles & Samples [Link]

Dim Width As Single = [Link]

Dim Height As Single = [Link]

' Set the StringFormat to center the text.

Dim string_format As New StringFormat

string_format.Alignment = [Link]

string_format.LineAlignment = [Link]

Dim layout_rect As New RectangleF(X, Y, Width, Height)

Dim InitialState As [Link] = [Link]()

[Link](Word, New Font(FontType, FontSize), [Link], layout_rect, string_format)

' Translate to the origin, rotate, and translate back.

[Link](-Width \ 2 - X, -Height \ 2 - Y, [Link])

[Link](Angle, [Link])

[Link](Width \ 2 + X, Height \ 2 + Y, [Link])

' Draw the text and layout rectangle.

[Link] = [Link]

[Link](Word, New Font(FontType, FontSize), [Link], layout_rect, string_format)

[Link](InitialState)

Posted on 8/10/2010 [Link] AM by Youssof

Dalia To Youssof
your method rotates a text not an image
but it is very interesting too!

Posted on 8/12/2010 [Link] AM by Dalia

ekalo Hi there,

I need same rotating from video (mediaplayer or another player), can we do?
Thnx.

Posted on 11/28/2010 [Link] AM by ekalo

Add Article Comment:


Name :
Email Address :

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 [Link] - .Net Articles & Samples [Link]

<< Create Splash Screen using [Link]

Serializing & Deserializing Objects Using Standard and Binary Formatter in [Link] >>

Disclaimer - Privacy
© 2002-2012 [Link]

6 of 6 13/07/2012 11:54 AM

You might also like