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. GDI+

GDI+

Scheduled Pinned Locked Moved C#
graphicswinformshelp
6 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.
  • V Offline
    V Offline
    Vladimir Georgiev
    wrote on last edited by
    #1

    Hello, I have the following code in a win app: // create bitmap from file Bitmap myBitmap = new Bitmap(textBox1.Text); Graphics g = Graphics.FromImage(myBitmap); g.RotateTransform(30); //rotate 30 degrees // create a new bitmap from the Graphics object Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g); // save the new bitmap to disk next.Save("c:/documents and settings/vortex/Desktop/file.jpg"); When this code is executed, an empty image file with the right dimensions is stored - just a blank (white) image... I tried without rotating, but nothing happened either. I would appreciate if you could give me any hints about the problem. Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

    M L 2 Replies Last reply
    0
    • V Vladimir Georgiev

      Hello, I have the following code in a win app: // create bitmap from file Bitmap myBitmap = new Bitmap(textBox1.Text); Graphics g = Graphics.FromImage(myBitmap); g.RotateTransform(30); //rotate 30 degrees // create a new bitmap from the Graphics object Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g); // save the new bitmap to disk next.Save("c:/documents and settings/vortex/Desktop/file.jpg"); When this code is executed, an empty image file with the right dimensions is stored - just a blank (white) image... I tried without rotating, but nothing happened either. I would appreciate if you could give me any hints about the problem. Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

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

      The constructore you used for your second Bitmap is wrong, its just use resolution of graphic object. You have to use Bitmap.Clone() method to create copy of your Bitmap. Mazy "I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein

      V 1 Reply Last reply
      0
      • M Mazdak

        The constructore you used for your second Bitmap is wrong, its just use resolution of graphic object. You have to use Bitmap.Clone() method to create copy of your Bitmap. Mazy "I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein

        V Offline
        V Offline
        Vladimir Georgiev
        wrote on last edited by
        #3

        It seems you understood the whole point wrongly... My intentions are to load a bitmap, manipulate it (e.g. Rotate it), and finally save it to another file... I thought the steps I described ( Bitmap->Graphics->Bitmap->file) could do it, but there was something wrong in that code. I strictly followed the MSDN documentation, but still I was unable to achieve this... "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

        1 Reply Last reply
        0
        • V Vladimir Georgiev

          Hello, I have the following code in a win app: // create bitmap from file Bitmap myBitmap = new Bitmap(textBox1.Text); Graphics g = Graphics.FromImage(myBitmap); g.RotateTransform(30); //rotate 30 degrees // create a new bitmap from the Graphics object Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g); // save the new bitmap to disk next.Save("c:/documents and settings/vortex/Desktop/file.jpg"); When this code is executed, an empty image file with the right dimensions is stored - just a blank (white) image... I tried without rotating, but nothing happened either. I would appreciate if you could give me any hints about the problem. Thank you in advance. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Vladimir Georgiev wrote: // create a new bitmap from the Graphics object Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g); Dont do that! Just save "myBitmap" top secret

          V 1 Reply Last reply
          0
          • L leppie

            Vladimir Georgiev wrote: // create a new bitmap from the Graphics object Bitmap next = new Bitmap(myBitmap.Width, myBitmap.Height, g); Dont do that! Just save "myBitmap" top secret

            V Offline
            V Offline
            Vladimir Georgiev
            wrote on last edited by
            #5

            Saving myBitmap does not save the rotated bitmap: // file is a 24-bit .bmp file Bitmap myBitmap = new Bitmap(textBox1.Text); Graphics g = Graphics.FromImage(myBitmap); g.RotateTransform(30); myBitmap.Save("c:/documents and settings/vortex/Desktop/file123.bmp"); My main purpose is to open a bitmap, get some pixels from it, calculate the rotation degree based on those pixels, rotate and save the bitmap. MSDN says that you could create a Graphics object from a bitmap, and vice-versa as well... But it does not work... Any help is highly appreciated. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

            L 1 Reply Last reply
            0
            • V Vladimir Georgiev

              Saving myBitmap does not save the rotated bitmap: // file is a 24-bit .bmp file Bitmap myBitmap = new Bitmap(textBox1.Text); Graphics g = Graphics.FromImage(myBitmap); g.RotateTransform(30); myBitmap.Save("c:/documents and settings/vortex/Desktop/file123.bmp"); My main purpose is to open a bitmap, get some pixels from it, calculate the rotation degree based on those pixels, rotate and save the bitmap. MSDN says that you could create a Graphics object from a bitmap, and vice-versa as well... But it does not work... Any help is highly appreciated. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Vladimir Georgiev wrote: g.RotateTransform(30); I think you are reading the function wrong. This just adjusts your "perspective" from a drawing point of view. IOW anything drawn after that will be "tilted". Thats said do this:

              Bitmap myBitmap = new Bitmap(textBox1.Text);
              Bitmap newb = myBitmap.Clone() as Bitmap;
              Graphics g = Graphics.FromImage(newb);
              g.RotateTransform(30);
              g.DrawImage(myBitmap);
              newb.Save("c:/documents and settings/vortex/Desktop/file123.bmp");

              top secret

              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