From 84ee32f402668bad757150ebd4e80d493ce2d9d2 Mon Sep 17 00:00:00 2001 From: "de@itstall.de" <de@itstall.de> Date: Tue, 4 Feb 2020 09:38:30 +0100 Subject: [PATCH] =?UTF-8?q?Kompassrose=20wieder=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wetterstation/Form1.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Wetterstation/Form1.cs b/Wetterstation/Form1.cs index e282688..30a3cad 100644 --- a/Wetterstation/Form1.cs +++ b/Wetterstation/Form1.cs @@ -265,9 +265,29 @@ namespace Wetterstation lbWindSpeed.Invoke(new Action(() => { lbWindSpeed.Text = weatherData.windSpeed + " ms"; })); lbWindricht.Invoke(new Action(() => { lbWindricht.Text = weatherData.windDeg + " °"; })); lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData.pressure + " mbar"; })); + pictureBox1.Invoke(new Action(() => { + pictureBox1.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("WindRose_neu"), (int)weatherData.windDeg); + })); + } catch (Exception ignored) { } } + private Bitmap RotateImage(Bitmap bmp, float angle) + { + float height = bmp.Height; + float width = bmp.Width; + int hypotenuse = System.Convert.ToInt32(System.Math.Floor(Math.Sqrt(height * height + width * width))); + Bitmap rotatedImage = new Bitmap(hypotenuse, hypotenuse); + using (Graphics g = Graphics.FromImage(rotatedImage)) + { + g.TranslateTransform((float)rotatedImage.Width / 2, (float)rotatedImage.Height / 2); //set the rotation point as the center into the matrix + g.RotateTransform(angle); //rotate + g.TranslateTransform(-(float)rotatedImage.Width / 2, -(float)rotatedImage.Height / 2); //restore rotation point into the matrix + g.DrawImage(bmp, (hypotenuse - width) / 2, (hypotenuse - height) / 2, width, height); + } + return rotatedImage; + } + public void updateFormForecast(String message) { -- GitLab