473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.

My thanks in advance

Sep 22 '06 #1
5 2515
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

Ricardo Furtado wrote:
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.

My thanks in advance
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

Ricardo Furtado wrote:
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.

My thanks in advance

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.

My thanks in advance
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.

My thanks in advance

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.

Ricardo Furtado

"Ricardo Furtado" wrote:
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.
>
>My thanks in advance
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 to get the affect of grabbing the corner of the...
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 old image is stretched first to the new image...
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 matter what I try the page is constantly reloading the...
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: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or...
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 flipping, but i cant get the rotating to work....
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 world. The best way seems to be a javascript. In...
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 part of my web page, allow it to screen for x...
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 main feature image? This is set up in...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.