![](/img/trans.png)
[英]How can I convert a Bing maps quadkey into zoom level, x-coordinate and y-coordinate using PHP?
[英]How can I make my smiley (made with Windows Forms) relative, meaning that giving it a different (x,y) coordinate, it'll stay the same?
我在 'tekenScherm' (=drawScreen) 方法中做了一個笑臉,給定 x、y、w (=width) 和 h (=height) 變量。 這些變量的基值為 (100, 50, 300, 300)。 如果你在我的代碼中輸入這些值,你會得到一個笑臉。
現在,我希望能夠調整這些 x、y、w 和 h 值,以便笑臉保持相對相同。
我已經知道如何對 x 和 y 坐標執行此操作,因此例如,當您更改 x 坐標時,左眼將隨 x + 50 變化,右眼將隨 x + 170 變化,所以它保持相對相同的。
現在,問題是眼睛和嘴巴的寬度和高度。 我希望能夠更改寬度和高度變量('w'、'h'),並使笑臉保持相對相同。 我已經嘗試了各種各樣的事情,困惑了幾個小時,但我似乎無法讓它發揮作用。
這是代碼:
namespace Smiley2
{
class HalloForm : Form
{
public HalloForm()
{
this.Text = "Smiley";
this.BackColor = Color.White;
this.Size = new Size(500, 500);
this.Paint += this.tekenScherm;
}
void tekenScherm(object obj, PaintEventArgs pea)
{
float x, y, w, h, wOogLinks, wOogRechts;
x = 100; y = 50; w = 300; h = 300;
Pen pen = new Pen(Brushes.Black);
pea.Graphics.FillEllipse(Brushes.Yellow, x, y, w, h);
pea.Graphics.DrawEllipse(pen, x, y, w, h);
pea.Graphics.FillEllipse(Brushes.White, x + 50, y + 50, 75 * (w / 300), 75 / 300f * h);
pea.Graphics.FillEllipse(Brushes.White, x + 170, y + 50, 75 * (w / 300), 75 / 300f * h);
pea.Graphics.DrawArc(pen, x + 90, y + 135, 125f / 300 * w, 100f / 300 * h, 0, 180);
}
}
class HalloWin3
{
static void Main()
{
HalloForm scherm;
scherm = new HalloForm();
Application.Run(scherm);
}
}
}
可以通過計算寬度和高度比例,然后將這些值與每個相關值相乘來完成。 X 和 Y 仍然給出您的偏移量,現在您可以根據需要更改 w 和 h,並且這些值將獨立縮放。
void tekenScherm(object obj, PaintEventArgs pea)
{
float x, y, w, h, wOogLinks, wOogRechts;
x = 100; y = 50; w = 300; h = 300;
float scaleW = w / 300f;
float scaleH = h / 300f;
Pen pen = new Pen(Brushes.Black);
pea.Graphics.FillEllipse(Brushes.Yellow, x, y, w, h);
pea.Graphics.DrawEllipse(pen, x, y, w, h);
pea.Graphics.FillEllipse(
Brushes.White,
x + 50 * scaleW,
y + 50 * scaleH,
75 * scaleW,
75 * scaleH);
pea.Graphics.FillEllipse(
Brushes.White,
x + 170 * scaleW,
y + 50 * scaleH,
75 * scaleW,
75 * scaleH);
pea.Graphics.DrawArc(
pen,
x + 90 * scaleW,
y + 135 * scaleH,
125f * scaleW,
100f * scaleH,
0,
180);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.