我正在尝试使用鼠标轮放大图片框。使用以下变量:
public static int offsetX = 0;
public static int offsetY = 0;
public static double scale = .05;我在画框上画了一系列多边形。但是,我希望左下角引用0,所以我用-y绘制表单中的所有内容。所绘制的点受上述变量的影响,但实际点保持不变。
void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
scale += .025;
else
scale -= .025;
pictureBox1.Invalidate();
}当鼠标轮向前移动时,我会增加缩放变量,并刷新盒子。它使用picturebox画法中的代码重新绘制:
Graphics g = e.Graphics;
foreach (Member m in activeTruss.members)
{
if (m.Visible == true)
{
Point[] pointArray = new Point[m.poly.Points.Count()];
int index = 0;
foreach (System.Windows.Point p in m.poly.Points)
{
pointArray[index].X = (int)((p.X + offsetX) * scale);
pointArray[index].Y = (int)-((p.Y + offsetY) * scale);
index++;
}
SolidBrush myBrush = new SolidBrush(m.color);
g.FillPolygon(myBrush, pointArray);
}
}它缩放正确的数量,但它似乎放大到左上角,因为偏移保持不变。相反,当放大时是正确的。当我转动鼠标轮时,应该如何编辑偏移量,以便直接向鼠标下方的点进行缩放?
发布于 2012-05-30 00:54:57
如果你想把你的变焦
double offsetX = scale/2
double offsetY = scale/2更新
要回答关于翻转图片的第二部分,听起来你并没有区分图片的x,y和x,y的屏幕坐标。通常,屏幕坐标从屏幕顶部开始,所以左上角是0,0,但是当您绘制图片时,图片的0,0位于左下角,所以使用-y。您要做的是开始绘制从0,0到0,MAXY没有翻转。对于这个实现细节,您的代码将帮助很多hehe :)
https://stackoverflow.com/questions/10808105
复制相似问题