缩放x和y坐标到Form/pictureBox位置.c#



通俗地说,我的Form2是游戏中实际"迷你地图"之外的外部"迷你地图"。

正如你在我的Form2中所看到的,我所绘制的红点与游戏中的"迷你地图"(即黄点)的位置不同。

在DebugView中,你可以看到我的字符X和Y的位置(charX &谨慎的)。

坐标以int x &在我的Form2类文件的函数中int y。

我的pictureBox1中的图像(即上面当前示例图片中的图像)是从我的服务器(url= "http://randomspam.co/MAP/103000000.img/miniMap.canvas.png")中提取的。

下面的代码是我到目前为止的进度注释。

请注意,pictureBox1的位置被设置为0,0。

错误如下:

1)我的外部小地图上的红点位置=我的角色在游戏中的小地图上的位置。

2)红点持续闪烁(出现&消失)

3)在pictureBox上显示的工具提示在显示和不显示方面确实滞后。

如果有人知道如何帮助我目前的情况(因为我迷路了),请,任何东西都是感激的。

谢谢。

好的,我们把它分成几个主题:

1)位置:

这里你必须匹配红点的位置到新的大小,这是回答了几次之前,看看这个->我如何转换XY坐标和高度/宽度缩放图像到原始大小的图像?

2)双缓冲区停止闪烁:

public void DrawWhatever(Graphics graphics, int cx, int cy)
{
    Graphics g;
    Bitmap buffer = null;
    buffer = new Bitmap([image width], [image height], graphics);
    g = Graphics.FromImage(buffer);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    // Draw a circle.
    Pen p = new Pen(Color.Red,1)
    g.DrawEllipse(p,cx,cy,30,30); //example values
    graphics.DrawImage(buffer, 0, 0);
    g.Dispose();
}

3)提示:

检查双缓冲区算法,让我知道

有一个小地图的副本:

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Bitmap bmpClone = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics objGraphics = Graphics.FromImage(bmpClone);
objGraphics.DrawImage(pictureBox1.Image, 0, 0);
objGraphics.Dispose();
bmp = (Bitmap)bmpClone.Clone();
pictureBox1.Image = bmp;

现在在任何无效操作之前:

Graphics objGraphics = Graphics.FromImage(bmp);
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
objGraphics.DrawImage(bmpClone, 0, 0);
objGraphics.FillEllipse(Brushes.Red, cx, cy, 5, 5)
objGraphics.Dispose();
pictureBox1.Invalidate();

你不需要在pictureBox1_Paint

瓦尔特

最新更新