OpenHardwareMonitor.GUI.SensorNotifyIcon.CreatePercentageIcon C# (CSharp) Method

CreatePercentageIcon() private method

private CreatePercentageIcon ( ) : Icon
return System.Drawing.Icon
        private Icon CreatePercentageIcon()
        {
            try {
            graphics.Clear(Color.Transparent);
              } catch (ArgumentException) {
            graphics.Clear(Color.Black);
              }
              graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height);
              float value = sensor.Value.GetValueOrDefault();
              float y = 0.16f * (100 - value);
              graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y);
              graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);

              BitmapData data = bitmap.LockBits(
            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
            ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
              byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4];
              Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
              bitmap.UnlockBits(data);

              return IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
            PixelFormat.Format32bppArgb);
        }