【发布时间】:2014-11-08 00:10:23
【问题描述】:
您好,我接到了将 java 应用程序转换为 c# windows 窗体应用程序的任务。该程序显示一个 Mandelbrot,然后允许用户放大。我已经设法显示 Mandelbrot 甚至缩放。但是,当拖动框进行缩放时,框本身不会显示,这意味着用户无法看到他们将放大到哪个区域。
我认为我需要在拖动时调用绘制矩形的更新函数这是我认为相关的代码。
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//e.consume();
if (action)
{
xs = e.X;
ys = e.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
int z, w;
//e.consume();
if (action)
{
xe = e.X;
ye = e.Y;
if (xs > xe)
{
z = xs;
xs = xe;
xe = z;
}
if (ys > ye)
{
z = ys;
ys = ye;
ye = z;
}
w = (xe - xs);
z = (ye - ys);
if ((w < 2) && (z < 2))
initvalues();
else
{
if (((float)w > (float)z * xy))
ye = (int)((float)ys + (float)w / xy);
else
xe = (int)((float)xs + (float)z * xy);
xende = xstart + xzoom * (double)xe;
yende = ystart + yzoom * (double)ye;
xstart += xzoom * (double)xs;
ystart += yzoom * (double)ys;
}
xzoom = (xende - xstart) / (double)x1;
yzoom = (yende - ystart) / (double)y1;
mandelbrot();
rectangle = false;
Refresh();
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
//e.consume();
if (action)
{
xe = e.X;
ye = e.Y;
rectangle = true;
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g1 = e.Graphics;
g1.DrawImage(bitmap, 0, 0, x1, y1);
g1.Dispose();
}
public void paint(Graphics g1)
{
update(g1);
}
public void update(Graphics g1)
{
Pen pen = new Pen(Color.White);
g1.DrawImage(bitmap, 0, 0, x1, y1);
if (rectangle)
{
if (xs < xe)
{
if (ys < ye) g1.DrawRectangle(pen, xs, ys, (xe - xs), (ye - ys));
else g1.DrawRectangle(pen, xs, ye, (xe - xs), (ys - ye));
}
else
{
if (ys < ye) g1.DrawRectangle(pen, xe, ys, (xs - xe), (ye - ys));
else g1.DrawRectangle(pen, xe, ye, (xs - xe), (ys - ye));
}
pen.Dispose();
}
}
【问题讨论】:
-
同班同学应该互相交流。这是你同学问的一个问题的重复:stackoverflow.com/questions/26721685/…
-
我看过那里,似乎没有帮助!
标签: c# bitmap zooming fractals