C#用风旋转箭头

时间:2014-06-22 19:55:40

标签: c#

我正在尝试旋转箭头并将其放在罗盘图像中以指示风向。首先,我使用了一个点并且它正在工作但是现在有了箭头它有时会指向错误的方向。这是我用来旋转图像并将其放在圆圈周围的代码。问题在于图像旋转。

问题是,背面图像是静态的,上面写有度数的圆圈,我以前只是在风度上放置一个点,但现在我想把箭头放在圆圈的边缘上我正在使用代码Bitmap imagemrodada = rotateImage(newSeta, wind_degrees + 90);的方向,但箭头并没有指向我想要的方向,在这个链接中有一个我想要做的风向相同的例子。 http://www.wunderground.com/global/stations/03772.html

if (Convert.ToInt32(wind_kph) > 0)
{
    Image image1 = Image.FromFile(arquivo_display);
    Image image2 = Image.FromFile(@"C:\Users\red\Desktop\arrow-06.png");
    Bitmap newPonto = (Bitmap) new Bitmap(image1);
    Bitmap newSeta = (Bitmap) new Bitmap(image2);
    image1.Dispose();
    image1 = null;
    image2.Dispose();
    image2 = null;
    using (Graphics g = Graphics.FromImage(newPonto))
    {
        Double distanceFromCenter = 45;
        Bitmap imagemrodada = rotateImage(newSeta, wind_degrees + 90);
        Console.WriteLine(wind_degrees + 90);
        Double angleInDegrees = wind_degrees - 90;
        Double angleAsRadians = (angleInDegrees*Math.PI)/180.0;
        Double centerX = 95;
        Double centerY = 95;
        Double x = centerX + Math.Cos(angleAsRadians)*distanceFromCenter;
        Double y = centerY + Math.Sin(angleAsRadians)*distanceFromCenter;
        g.DrawImageUnscaled(imagemrodada, Convert.ToInt32(x), Convert.ToInt32(y));
        newPonto.Save(arquivo_display);
        newPonto.Dispose();
        newPonto = null;
        newSeta.Dispose();
        newSeta = null;
       }

0 个答案:

没有答案