Is it possible to rotate a graphic image

Posted on 2005-04-06
Last Modified: 2010-04-23
I suppose this could be a very simple task, that i simply do not have the understanding of - but is it possible to (or does anyone know how to) rotate an image. (e.g. a jpeg) through a set number of degrees (not necessarily 90, 180, 270 though, but an arbitary amount)

Any help would be very much appreciated, as I am complete stumped.

Question by:swtiley
    LVL 96

    Expert Comment

    by:Bob Learned
    LVL 32

    Expert Comment

    Simple example of how to rotate a picture and display it in a picturebox:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            'Load up an image from disk
            Dim imgOrig As Image = Image.FromFile("c:\image.jpg")
            'Make a copy
            Dim imgClone As Image = imgOrig.Clone

            'Angle of rotation in degrees
            Dim angle As Single
            angle = 33

            'Create the graphics object to draw onto
            Dim g As Graphics = Graphics.FromImage(imgOrig)
            'Clear the picture and give us a black background

            'Translate to the center of the image
            g.TranslateTransform(imgClone.Width / 2, imgClone.Height / 2)
            'Rotate about center of image
            'Translate back
            g.TranslateTransform(-imgClone.Width / 2, -imgClone.Height / 2)

            'Draw the image
            g.DrawImage(imgClone, New Point(0, 0))
            'Display the results in a PictureBox
            PictureBox1.Image = imgOrig.Clone

            'clean up
        End Sub
    LVL 32

    Accepted Solution

    Forgot this...


    Imports System.drawing
    Imports System.drawing.imaging
    LVL 1

    Author Comment

    Thanks Erick - fantastic answer


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now