Home All Groups Group Topic Archive Search About
Author
22 Sep 2006 3:31 PM
Ricardo Furtado
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

Author
22 Sep 2006 4:13 PM
rowe_newsgroups
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:
Show quoteHide quote
> 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
Author
23 Sep 2006 7:32 AM
Ricardo Furtado
yes i do. The user will rotate the image by pressing the mouse button on the
corners of the picturebox

Show quoteHide quote
"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
>
>
Author
23 Sep 2006 10:08 AM
gene kelley
On Fri, 22 Sep 2006 08:31:02 -0700, Ricardo Furtado
<RicardoFurt***@discussions.microsoft.com> wrote:

Show quoteHide quote
>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
Author
25 Sep 2006 2:09 PM
Ricardo Furtado
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


Show quoteHide quote
"gene kelley" wrote:

> On Fri, 22 Sep 2006 08:31:02 -0700, Ricardo Furtado
> <RicardoFurt***@discussions.microsoft.com> 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
>
> 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
>
Author
26 Sep 2006 7:25 AM
Ricardo Furtado
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

Show quoteHide quote
"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
> > <RicardoFurt***@discussions.microsoft.com> 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
> >
> > 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
> >