我只想移动图片框的某个部分,但我只能移动那个部分。目前我可以从左到右移动它,但我只想移动它的尖端。
private float angle = 0.0f;
Image image;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right) angle += 1;
else if (e.KeyCode == Keys.Left) angle -= 1;
int a = pictureBox1.Location.X;
int b = pictureBox1.Location.Y;
if (e.KeyCode == Keys.Right) a += 5;
else if (e.KeyCode == Keys.Left) a -= 5;
pictureBox2.Location = new Point(a, b);
RotateImage(pictureBox1, image, angle);
}
private void RotateImage(PictureBox pb, Image img, float angle)
{
//Store our old image so we can delete it
Image oldImage = pb.Image;
pb.Image = RotateImage(img, angle);
if (oldImage != null)
oldImage.Dispose();
}
public static Bitmap RotateImage(Image image, float angle)
{
return RotateImageFinal(image, new PointF((float)image.Width / 2, (float)image.Height / 2), angle);
}
public static Bitmap RotateImageFinal(Image image, PointF offset, float angle)
{
//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;
}
private void Form1_Load(object sender, EventArgs e)
{ //Just to store the address of the 'arrow' image.
string path = Directory.GetCurrentDirectory();
image = new Bitmap(path + "/img/arrow.bmp");
}
我想倾斜的对象的 PS,我有兴趣固定底部同时只移动顶部 http://imgur.com/H2ic2g7