472,331 Members | 1,851 Online

# rotating image

I'm trying, for a week or two, to create a procedure in order to rotate the
image in any picturebox control in a cephalometry software. I've found a web
site that shows how that can be done:
http://vb-helper.com/index_vbnet.html
but the problem is that the image doesn't stay at the top, instead, the
image is created upon another bitmap, even larger, and at its right corner.
I've already tryed to cut the right corner, with the right dimensions, create
a new bitmap with the right dimensions and paste the part of the image
belonging to the rotated image in the x=0, y=0 coordenates. That almost
works, but the image is not big enough because, once the image is rotated the
size (width/height) of the image is increased (Pythagoras Theorem). I've
tryed several things, and i'm really, really, really desperate. Can you help
ps: if you set the picturebox sizemode as "stretchImage", which is what i
need to use in the software i'm developing, the image seems to get smaller,
although what's happening is what i've explained previously.

Sep 22 '06 #1
5 2436
Do you have to rotate the image by a certain number or degrees? If not
check out the RotateFlip() method of the system.drawing.image object.
It only rotates in increments of 90 degrees though.

Thanks,

Seth Rowe

I'm trying, for a week or two, to create a procedure in order to rotate the
image in any picturebox control in a cephalometry software. I've found a web
site that shows how that can be done:
http://vb-helper.com/index_vbnet.html
but the problem is that the image doesn't stay at the top, instead, the
image is created upon another bitmap, even larger, and at its right corner.
I've already tryed to cut the right corner, with the right dimensions, create
a new bitmap with the right dimensions and paste the part of the image
belonging to the rotated image in the x=0, y=0 coordenates. That almost
works, but the image is not big enough because, once the image is rotated the
size (width/height) of the image is increased (Pythagoras Theorem). I've
tryed several things, and i'm really, really, really desperate. Can you help
ps: if you set the picturebox sizemode as "stretchImage", which is what i
need to use in the software i'm developing, the image seems to get smaller,
although what's happening is what i've explained previously.

Sep 22 '06 #2
yes i do. The user will rotate the image by pressing the mouse button on the
corners of the picturebox

"rowe_newsgroups" wrote:
Do you have to rotate the image by a certain number or degrees? If not
check out the RotateFlip() method of the system.drawing.image object.
It only rotates in increments of 90 degrees though.

Thanks,

Seth Rowe

I'm trying, for a week or two, to create a procedure in order to rotate the
image in any picturebox control in a cephalometry software. I've found a web
site that shows how that can be done:
http://vb-helper.com/index_vbnet.html
but the problem is that the image doesn't stay at the top, instead, the
image is created upon another bitmap, even larger, and at its right corner.
I've already tryed to cut the right corner, with the right dimensions, create
a new bitmap with the right dimensions and paste the part of the image
belonging to the rotated image in the x=0, y=0 coordenates. That almost
works, but the image is not big enough because, once the image is rotated the
size (width/height) of the image is increased (Pythagoras Theorem). I've
tryed several things, and i'm really, really, really desperate. Can you help
ps: if you set the picturebox sizemode as "stretchImage", which is what i
need to use in the software i'm developing, the image seems to get smaller,
although what's happening is what i've explained previously.

Sep 23 '06 #3
On Fri, 22 Sep 2006 08:31:02 -0700, Ricardo Furtado
<Ri************@discussions.microsoft.comwrote:
>I'm trying, for a week or two, to create a procedure in order to rotate the
image in any picturebox control in a cephalometry software. I've found a web
site that shows how that can be done:
http://vb-helper.com/index_vbnet.html
but the problem is that the image doesn't stay at the top, instead, the
image is created upon another bitmap, even larger, and at its right corner.
I've already tryed to cut the right corner, with the right dimensions, create
a new bitmap with the right dimensions and paste the part of the image
belonging to the rotated image in the x=0, y=0 coordenates. That almost
works, but the image is not big enough because, once the image is rotated the
size (width/height) of the image is increased (Pythagoras Theorem). I've
tryed several things, and i'm really, really, really desperate. Can you help
ps: if you set the picturebox sizemode as "stretchImage", which is what i
need to use in the software i'm developing, the image seems to get smaller,
although what's happening is what i've explained previously.

The example at the posted link works as expected. It's not clear to me, or
apparently anyone else, as to what you are trying to describe.

Gene

Gene
Sep 23 '06 #4
i'm trying to rotate an image with an angle set by the user.
I know this is very dificult to show you, the only way was if you could see
the image. but imagine this:
- i have an image of a patient.
- an image of a tooth is drawn on the patient face
- the user can rotate (resize it, and drag it) the image of the tooth in
order put the image of the tooth on top of the other image where the tooth
is.
I've found some code for the rotation of the image, but the problem has to
do with the size of the image after the rotation function. The imagem is
always getting bigger and the tooth is always looking smaller
the code is the following:

Public Sub rotateImg(ByRef imagem As Image, ByVal sngAngle As Single)
' Copy the output bitmap from the source image.
Dim bm_in As New Bitmap(imagem)

' 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 = Single.Parse(sngAngle) * 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

' Translate so X >= 0 and Y >=0 for all corners.
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

' Create an output Bitmap and Graphics object.
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * _
ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)

' Drop the last corner lest we confuse DrawImage,
' which expects an array of three corners.
ReDim Preserve corners(2)

' Draw the result onto the output Bitmap.
gr_out.DrawImage(bm_in, corners)

' Display the result.

imagem = bm_out

End Sub
"gene kelley" wrote:
On Fri, 22 Sep 2006 08:31:02 -0700, Ricardo Furtado
<Ri************@discussions.microsoft.comwrote:
I'm trying, for a week or two, to create a procedure in order to rotate the
image in any picturebox control in a cephalometry software. I've found a web
site that shows how that can be done:
http://vb-helper.com/index_vbnet.html
but the problem is that the image doesn't stay at the top, instead, the
image is created upon another bitmap, even larger, and at its right corner.
I've already tryed to cut the right corner, with the right dimensions, create
a new bitmap with the right dimensions and paste the part of the image
belonging to the rotated image in the x=0, y=0 coordenates. That almost
works, but the image is not big enough because, once the image is rotated the
size (width/height) of the image is increased (Pythagoras Theorem). I've
tryed several things, and i'm really, really, really desperate. Can you help
ps: if you set the picturebox sizemode as "stretchImage", which is what i
need to use in the software i'm developing, the image seems to get smaller,
although what's happening is what i've explained previously.

The example at the posted link works as expected. It's not clear to me, or
apparently anyone else, as to what you are trying to describe.

Gene

Gene
Sep 25 '06 #5
Thanks to all of you. I've managed to solve the problem:
like i said, every time i rotated the image, the image was getting bigger,
because it was being resized. The way i fix the problem was very simple: Now
i'm always rotating the original image, instead of the rotated image, i just
have to know the angle the user rotated the image in the last time in order
to add the next rotation angle to the previous one.

Thanks, once again.

i'm trying to rotate an image with an angle set by the user.
I know this is very dificult to show you, the only way was if you could see
the image. but imagine this:
- i have an image of a patient.
- an image of a tooth is drawn on the patient face
- the user can rotate (resize it, and drag it) the image of the tooth in
order put the image of the tooth on top of the other image where the tooth
is.
I've found some code for the rotation of the image, but the problem has to
do with the size of the image after the rotation function. The imagem is
always getting bigger and the tooth is always looking smaller
the code is the following:

Public Sub rotateImg(ByRef imagem As Image, ByVal sngAngle As Single)
' Copy the output bitmap from the source image.
Dim bm_in As New Bitmap(imagem)

' 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 = Single.Parse(sngAngle) * 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

' Translate so X >= 0 and Y >=0 for all corners.
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

' Create an output Bitmap and Graphics object.
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * _
ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)

' Drop the last corner lest we confuse DrawImage,
' which expects an array of three corners.
ReDim Preserve corners(2)

' Draw the result onto the output Bitmap.
gr_out.DrawImage(bm_in, corners)

' Display the result.

imagem = bm_out

End Sub
"gene kelley" wrote:
On Fri, 22 Sep 2006 08:31:02 -0700, Ricardo Furtado
<Ri************@discussions.microsoft.comwrote:
>I'm trying, for a week or two, to create a procedure in order to rotate the
>image in any picturebox control in a cephalometry software. I've found a web
>site that shows how that can be done:
>http://vb-helper.com/index_vbnet.html
>but the problem is that the image doesn't stay at the top, instead, the
>image is created upon another bitmap, even larger, and at its right corner.
>I've already tryed to cut the right corner, with the right dimensions, create
>a new bitmap with the right dimensions and paste the part of the image
>belonging to the rotated image in the x=0, y=0 coordenates. That almost
>works, but the image is not big enough because, once the image is rotated the
>size (width/height) of the image is increased (Pythagoras Theorem). I've
>tryed several things, and i'm really, really, really desperate. Can you help
>ps: if you set the picturebox sizemode as "stretchImage", which is what i
>need to use in the software i'm developing, the image seems to get smaller,
>although what's happening is what i've explained previously.
>
The example at the posted link works as expected. It's not clear to me, or
apparently anyone else, as to what you are trying to describe.

Gene

Gene
Sep 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 1 by: Charles A. Lackman | last post by: Hello, I am trying to rotate a picturebox control. I have done some experimenting with rotating the image inside the picturebox, but I am trying... 5 by: John | last post by: I am rotating images at one location of my web site. My problem is if I set the width and height of the new image before I show the new image, the... 1 by: Grunt | last post by: Hi, I have been trying to put together a rotating banner. the code works but I am having a problem with the caching of the banner images. no... 14 by: mikeoley | last post by: Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this:... 9 by: Kraken | last post by: Hi, i have an assignment to open PPM images and prompt the user for either brightening, flipping or rotating the image. Ive done the brightening and... 3 by: avalence | last post by: Hello, I am trying to create a nice rotating earth globe (on mouse) on my web site, in order to display my professional relationships all over the... 1 by: kennykenn | last post by: Im having trouble startin to develop a rotating image banner, I have coded part of it (only pulling image from a db). My aim is to print an image to... 1 by: AR123 | last post by: Hi I want to set up a rotating banner. Not sure how to incorporate my rotating banner code into the code below. I want the rotating banner to be the... 5 by: Michael | last post by: Hello all, how could I rotate a server side image in asp.net and show it in web page? Thanks. 0 by: tammygombez | last post by: Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue.... 0 by: concettolabs | last post by: In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool... 0 by: better678 | last post by: Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented... 0 by: Kemmylinns12 | last post by: Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and... 0 by: CD Tom | last post by: This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right... 0 by: CD Tom | last post by: This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins... 0 by: antdb | last post by: Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was... 2 by: Matthew3360 | last post by: Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it... 0 by: AndyPSV | last post by: HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...