PDA

View Full Version : سوال: چرخش تصویر از نقطه دلخواه



mtsoft
سه شنبه 23 آبان 1391, 14:38 عصر
سلام خدمت همه دوستان عزیز

من با کد زیر یک تصویر رو می چرخونم و لی مشکل من اینه که تصویر از گوشه سمت چپ بالای می چرخه و من می خوام از نقطه دلخواه خودم مثلا مرکز تصویر بتنونم اون رو بچرخونم یا هر نقطه دیگه مثل عقربه های ساعت که تقریبا از تهشون یکم بالاتر می چرخن میشه من رو راهنمایی بفرمایید.



private void rotate(float daraje)
{
g = pictureBox1.CreateGraphics();
g.Clear(pictureBox1.BackColor);
g.TranslateTransform(pictureBox1.Width / 2, pictureBox1.Height / 2);
g.RotateTransform(daraje);
g.TranslateTransform(-pictureBox1.Width / 2, -pictureBox1.Height / 2);
g.DrawImage(Image.FromFile("1.png"), pictureBox1.Width / 2, pictureBox1.Height / 2);
g.Dispose();
}

Reza,M
سه شنبه 23 آبان 1391, 15:17 عصر
سلام


public class Class1
{


public static Bitmap RotateImage(Image image, float angle)
{
return RotateImage(image, new PointF((image.Width) / 2, (image.Height) / 2), angle);
}

public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
//If image Is Nothing Then
//Throw New ArgumentNullException("image")
//End If

//create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolutio n, 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(System.Convert.ToSingle(- offset.X), System.Convert.ToSingle(- offset.Y));

//draw passed in image onto graphics object
g.DrawImage(image, new PointF(0, 0));

return rotatedBmp;
}
}


صدا زدن



private void RotateImage(PictureBox pb, Image img, float angle)
{
if (img == null || pb.Image == null)
{
return;
}
}


و


RotateImage(PictureBox1, image, angle);

موفق باشید

hadidan
یک شنبه 22 اردیبهشت 1392, 12:01 عصر
سلام
میشه لطفا نمونه سورس هم بزارید:قلب:، کارم گیره :(