This is about Rotating an image
-
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?
-
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?
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:
-
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:
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
-
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
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:
-
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:
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
-
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
Ya, my frazzled mind was stuck on 90 degrees :)
I'm largely language agnostic
After a while they all bug me :doh:
-
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:
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...
-
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: