Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. This is about Rotating an image

This is about Rotating an image

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Luckie
    wrote on last edited by
    #1

    private Bitmap rotateImage(Bitmap b, float angle) { Bitmap bmp1 = new Bitmap(b.Width, b.Height); Graphics g = Graphics.FromImage(bmp1); g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2); //rotation g.RotateTransform(angle); g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2); g.DrawImage(b, new Point(0, 0)); return bmp1; } I found this code in a site..This deals with Rotating an image.. But when i crop with this... Image is getting vanished on its edges.. How to perform rotation without any modifications in the image size? Any modidications in this or any clues?

    M 1 Reply Last reply
    0
    • L Luckie

      private Bitmap rotateImage(Bitmap b, float angle) { Bitmap bmp1 = new Bitmap(b.Width, b.Height); Graphics g = Graphics.FromImage(bmp1); g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2); //rotation g.RotateTransform(angle); g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2); g.DrawImage(b, new Point(0, 0)); return bmp1; } I found this code in a site..This deals with Rotating an image.. But when i crop with this... Image is getting vanished on its edges.. How to perform rotation without any modifications in the image size? Any modidications in this or any clues?

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #2

      If you rotate an image, unless it's a square the dimensions will change, only the area stays constant.

      Luckie wrote:

      Bitmap bmp1 = new Bitmap(b.Width, b.Height);

      The problem is above. You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.


      I'm largely language agnostic


      After a while they all bug me :doh:


      L D 2 Replies Last reply
      0
      • M MidwestLimey

        If you rotate an image, unless it's a square the dimensions will change, only the area stays constant.

        Luckie wrote:

        Bitmap bmp1 = new Bitmap(b.Width, b.Height);

        The problem is above. You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.


        I'm largely language agnostic


        After a while they all bug me :doh:


        L Offline
        L Offline
        Luckie
        wrote on last edited by
        #3

        MidwestLimey wrote:

        You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.

        Don't get you mate

        M 1 Reply Last reply
        0
        • L Luckie

          MidwestLimey wrote:

          You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.

          Don't get you mate

          M Offline
          M Offline
          MidwestLimey
          wrote on last edited by
          #4

          If for instance you have a 5x9 image, to rotate 90 or 270 degrees you would need a square of 9x5 for the resulting image to fit. Since it needs to also hold the original image it would need to be 9x9. If you're rotating by some discreet amount (see post below), you'll need to calculate how much room you'll need, size the original image appropriately and then resize the image afterwards to your required dimensions.


          I'm largely language agnostic


          After a while they all bug me :doh:


          L 2 Replies Last reply
          0
          • M MidwestLimey

            If you rotate an image, unless it's a square the dimensions will change, only the area stays constant.

            Luckie wrote:

            Bitmap bmp1 = new Bitmap(b.Width, b.Height);

            The problem is above. You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.


            I'm largely language agnostic


            After a while they all bug me :doh:


            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #5

            MidwestLimey wrote:

            You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.

            No, the largest it would need to be is the length of the diagonal (for a rotation that lays a diagonal along the X or Y axis). (x^2+y^2)^.5

            You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4.... -- El Corazon

            M 1 Reply Last reply
            0
            • D Dan Neely

              MidwestLimey wrote:

              You'll need to size the image appropriately, guarenteeing enough room for a rotated image to fit. At the very least the size will need to be a square of the largest dimension of the original image. You can crop the image appropriately afterwards.

              No, the largest it would need to be is the length of the diagonal (for a rotation that lays a diagonal along the X or Y axis). (x^2+y^2)^.5

              You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4.... -- El Corazon

              M Offline
              M Offline
              MidwestLimey
              wrote on last edited by
              #6

              Ya, my frazzled mind was stuck on 90 degrees :)


              I'm largely language agnostic


              After a while they all bug me :doh:


              1 Reply Last reply
              0
              • M MidwestLimey

                If for instance you have a 5x9 image, to rotate 90 or 270 degrees you would need a square of 9x5 for the resulting image to fit. Since it needs to also hold the original image it would need to be 9x9. If you're rotating by some discreet amount (see post below), you'll need to calculate how much room you'll need, size the original image appropriately and then resize the image afterwards to your required dimensions.


                I'm largely language agnostic


                After a while they all bug me :doh:


                L Offline
                L Offline
                Luckie
                wrote on last edited by
                #7

                MidwestLimey wrote:

                you'll need to calculate how much room you'll need, size the original image appropriately and then resize the image afterwards to your required dimensions.

                Any other way?

                Don't try to make someone love you..Try to be the one who can be loved...

                1 Reply Last reply
                0
                • M MidwestLimey

                  If for instance you have a 5x9 image, to rotate 90 or 270 degrees you would need a square of 9x5 for the resulting image to fit. Since it needs to also hold the original image it would need to be 9x9. If you're rotating by some discreet amount (see post below), you'll need to calculate how much room you'll need, size the original image appropriately and then resize the image afterwards to your required dimensions.


                  I'm largely language agnostic


                  After a while they all bug me :doh:


                  L Offline
                  L Offline
                  Luckie
                  wrote on last edited by
                  #8

                  Can u just modify it in the coding and reply or just quote the lines to be modified.. :)

                  Don't try to make someone love you..Try to be the one who can be loved...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups