简体   繁体   English

将x和y坐标缩放到Form / pictureBox位置。 C#

[英]Scale x and y coordinates to Form/pictureBox location. C#

My Form2 is in layman terms an external 'mini-map' off the actual 'mini-map' in-game. 我的Form2用外行术语来表示游戏中实际“迷你地图”的外部“迷你地图”。

As you can see on my Form2, my drawn red dot does not have the same location for my player when compared to the 'mini-map' in-game which is the yellow dot. 正如你在我的Form2上看到的那样,与游戏中的“迷你地图”(黄点)相比,我绘制的红点与我的玩家的位置不同。

In the DebugView, you can see my characters X and Y location (charX & charY). 在DebugView中,您可以看到我的字符X和Y位置(charX和charY)。

The coordinates are passed as int x & int y in a function to my Form2 class file. 坐标在函数中作为int x&int y传递给我的Form2类文件。

The image in my pictureBox1 (which is the image in the current example picture above) is pulled from my server (url= " http://randomspam.co/MAP/103000000.img/miniMap.canvas.png "). 我的pictureBox1中的图像(上面当前示例图片中的图像)是从我的服务器中提取的(url =“ http://randomspam.co/MAP/103000000.img/miniMap.canvas.png ”)。

Here is the following code with comments to my progress as of now. 以下是代码,其中包含对我目前进度的评论。

Please take note that the pictureBox1 location is set to 0,0. 请注意,pictureBox1位置设置为0,0。

The errors are as follows; 错误如下;

1) The red dot location on my external mini-map != the location of my character in the mini-map in-game. 1)我的外部迷你地图上的红点位置!=我的角色在游戏中的迷你地图中的位置。

2) The red dot consistently flickers (appears & disappears) 2)红点一直闪烁(出现和消失)

3) The tooltip when shown on the pictureBox is really lagging in revealing and dis-revealing itself. 3)在pictureBox上显示的工具提示在揭示和揭示自身方面确实滞后。

If anyone knows how to help out my current situation (as I am lost), please, anything is appreciated. 如果有人知道如何帮助我当前的情况(因为我迷路),拜托,任何事情都表示赞赏。

Thanks. 谢谢。

Ok, lets split this in topics: 好吧,让我们在主题中拆分:

1) Red Dot Location: 1)红点位置:

Here you have to match red dot position to the new size, this was answered several times before, see this -> How can I transform XY coordinates and height/width on a scaled image to an original sized image? 在这里你必须将红点位置与新尺寸相匹配,之前已经多次回答,请参阅 - > 如何将缩放图像上的XY坐标和高度/宽度转换为原始尺寸的图像?

2) Double Buffer to stop Flickering: 2)Double Buffer停止闪烁:

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) Tooltip: 3)工具提示:

Check double buffer algorithm and let me know 检查双缓冲算法并告诉我

Have a copy from the mini map: 从迷你地图中获取副本:

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;

Now before any invalidation do: 在任何无效之前做:

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();

You dont need anything inside pictureBox1_Paint 你在pictureBox1_Paint里面不需要任何东西

valter 瓦尔特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM