Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Rotating Image


Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2012, 01:27 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 127
Default Rotating Image


Is it possible to rotate an image other than with picturebox1.image.rotateflip(RotateFlipType.~~~~~)?
Not only is that function doing absolutely nothing, but I need to rotate an image 36 degrees at a time.
__________________
Amerigo
Reply With Quote
  #2  
Old 07-15-2012, 02:17 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default rotating an image using matrix transforms, DrawImage, and DrawImageUnscaled

Have you not heard of the .Net Matrix Class?

It has a rotate method that allows you to matrix transforms.
This thread has some matrix transforms examples in it.
(of course I know you'll want to cruise through the
MSDN "Matrix Representation of Transformations" page just for fun also..)

(Note: You can clip a graphic into a graphics path and transform rotate it that way
or use a texturebrush as a transform rotated brush image fill).

Another way is to rotate an image in VB .NET using DrawImage,
but performance-wise if you have do it hundreds of times second for animation purposes,
DrawImage can be somewhat "velocity challenged" on older computers.

This page has a picture spin animation test for DrawImage speed testing.
For comparison purposes you try passel's texturebrush car sprite rotation example
(attached to this post).

Lastly, DrawImage also works with Graphics.RotateTransform and you can substitute
the DrawImageUnscaled method for DrawImage (some claim it is slightly faster),
as in the "Function RotateImg" code from the bottom of this page:
Code:
Public Function RotateImg(ByVal bmpimage As Bitmap, ByVal angle As Single) As Bitmap
        Dim w As Integer = bmpimage.Width
        Dim h As Integer = bmpimage.Height
        Dim pf As PixelFormat = Nothing
        pf = bmpimage.PixelFormat
        Dim tempImg As New Bitmap(w, h, pf)
        Dim g As Graphics = Graphics.FromImage(tempImg)
        g.DrawImageUnscaled(bmpimage, 1, 1)
        g.Dispose()
        Dim path As New GraphicsPath()
        path.AddRectangle(New RectangleF(0.0F, 0.0F, w, h))
        Dim mtrx As New Matrix()
        'Using System.Drawing.Drawing2D.Matrix class
        
        mtrx.Rotate(angle)
        Dim rct As RectangleF = path.GetBounds(mtrx)
        Dim newImg As New Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf)
        g = Graphics.FromImage(newImg)
        g.TranslateTransform(-rct.X, -rct.Y)
        g.RotateTransform(angle)
        g.InterpolationMode = InterpolationMode.HighQualityBilinear
        g.DrawImageUnscaled(tempImg, 0, 0)
        g.Dispose()
        tempImg.Dispose()
        Return newImg
    End Function

Last edited by surfR2911; 07-15-2012 at 03:08 PM.
Reply With Quote
  #3  
Old 07-18-2012, 02:41 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 127
Default

Thank you very much.
__________________
Amerigo
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->