GDI+
-
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
-
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
The constructore you used for your second
Bitmap
is wrong, its just use resolution of graphic object. You have to useBitmap.Clone()
method to create copy of yourBitmap
. Mazy "I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein -
The constructore you used for your second
Bitmap
is wrong, its just use resolution of graphic object. You have to useBitmap.Clone()
method to create copy of yourBitmap
. Mazy "I think that only daring speculation can lead us further and not accumulation of facts." - Albert EinsteinIt 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
-
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
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
-
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
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
-
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
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");