效果图
private Bitmap GetPointerImg(Bitmap pointerImg, float angle, int w, int h ,int centerX, int centerY) { // 创建新的位图作为旋转后的图片 Bitmap rotatedImage = new Bitmap(w, h); // 创建一个Graphics对象,用于绘制旋转后的图片 using (Graphics g = Graphics.FromImage(rotatedImage)) { g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(centerX, centerY, 10, 10)); // 设置旋转中心点为图片中心 g.TranslateTransform(centerX, centerY); // 执行旋转 g.RotateTransform(angle); // 恢复旋转中心点到原位置 g.TranslateTransform(-centerX, -centerY); g.DrawImage(pointerImg, 0, centerY - pointerImg.Height / 2); } return rotatedImage; } private void pictureBox1_Click(object sender, EventArgs e) { int centerX = pictureBox1.Width / 2; int centerY = pictureBox1.Height / 2; var ea = (MouseEventArgs)e; double distance = Math.Sqrt(Math.Pow(ea.X - centerX, 2) + Math.Pow(ea.Y - centerY, 2));//点击处到圆心的距离 double angle = Math.Asin((centerY - ea.Y) / distance) * 180 / Math.PI; if (centerX < ea.X && centerY > ea.Y) angle = 180- angle;//第一象限 else if (centerX > ea.X && centerY < ea.Y) angle = 0;//第三象限 else if (centerX < ea.X && centerY < ea.Y) angle = 180;//第四象限 //double angle = 180 / (Math.PI * Math.Atan((centerY - ea.Y) / 1.0 * (centerX - ea.X))); text_Angle.Text = angle.ToString(); var bmp = GetPointerImg(Resources.valsalvaThresholdPointer, (float)angle, pictureBox1.Width, pictureBox1.Height, 124, 124); pictureBox1.Image = bmp; } private void btn_DrawPointer_Click(object sender, EventArgs e) { var angle = Convert.ToDouble(text_Angle.Text); var bmp = GetPointerImg(Resources.valsalvaThresholdPointer, (float)angle, pictureBox1.Width, pictureBox1.Height, 124, 124); pictureBox1.Image = bmp; }
标签:angle,圆盘,ea,pictureBox1,centerX,centerY,Math,指针 From: https://www.cnblogs.com/chixiner/p/17687995.html