Hi,
Am working in Image Processing application(Having picture box inside the User Control). In that i am doing Image Roatation based on the value entered in the text box. Image is rotating based on the given angle but 1 or 2 rotation original image got affected. I mean If the Image shape is Rectangle means it will become diagonal, round and so on.
Attached is the code.
Can anyone help me this to resolve.
Loading

FroglegPosted Jun 8, 2011, 5:02 PM
In the example I have uploaded, I used the image hypotenuse to scale the bitmap. A better way would be to calculate the distance between each of the four corners of the image in the horizontal and vertical planes. I've included an image of the "grid10.bmp" which I rotated in office imaging showing how it's done.
So if you save the image it's size would be the hypotenuse of the original width and height
also look here
http://www.vcskicks.com/image-rotate.php
Farooque AliPosted Jun 8, 2011, 6:36 AM
Am not able to attach the code in my post. So i have pasted my code below..
Code written in User Control
============================
public void RotateImage1(PictureBox pb, Image img, float angle)
{
img = pictureBox1.Image;
if (img == null || pb.Image == null)
return;
Image oldImage = pb.Image;
pb.Image = Utilities.RotateImage(img, angle);
if (oldImage != null)
{
oldImage.Dispose();
}
}
public sealed class Utilities
{
private Utilities()
{
}
public static Bitmap RotateImage(Image image, float angle)
{
var newBitmap = new Bitmap(image.Width, image.Height);
var graphics = Graphics.FromImage(newBitmap);
graphics.TranslateTransform((float)image.Width / 2, (float)image.Height / 2);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-(float)image.Width / 2, -(float)image.Height / 2);
graphics.DrawImage(image, new Point(0, 0));
return newBitmap;
//return RotateImage(image, new PointF((float)image.Width / 2, (float)image.Height / 2),angle);
}
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
if (image == null)
throw new ArgumentNullException("image");
//create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(rotatedBmp);
//Put the rotation point in the center of the image
g.TranslateTransform(offset.X, offset.Y);
//rotate the image
g.RotateTransform(angle);
//move the image back
g.TranslateTransform(-offset.X, -offset.Y);
//draw passed in image onto graphics object
g.DrawImage(image, new PointF(0, 0));
return rotatedBmp;
}
}
Jaganathan BantheswaranPosted Jun 8, 2011, 6:22 AM
There is no code attached !