Skip to content

Commit

Permalink
Add helper method for RGB24 convert
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasweimann committed May 19, 2024
1 parent 36c19d4 commit ddb8e32
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
using RxTelegram.Bot.Interface.BaseTypes;

namespace RxTelegram.Bot.Interface.ChatBackground;

public class BackgroundTypeWallpaper
public class BackgroundTypeWallpaper : BackgroundType
{

/// <summary>
/// Type of the background, always “wallpaper”
/// </summary>
public override string Type { get; } = "wallpaper";

/// <summary>
/// Document with the wallpaper
/// </summary>
public Document Document { get; set; }

/// <summary>
/// Dimming of the background in dark themes, as a percentage; 0-100
/// </summary>
public int DarkThemeDimming { get; set; }

/// <summary>
/// Optional. True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12
/// </summary>
public bool IsBlurred { get; set; }

/// <summary>
/// Optional. True, if the background moves slightly when the device is tilted
/// </summary>
public bool IsMoving { get; set; }
}
26 changes: 26 additions & 0 deletions src/RxTelegram.Bot/Utils/HexToRGB24Converter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Globalization;

namespace RxTelegram.Bot.Utils;

public class HexToRgb24
{
public int Convert(string hexColor) => int.Parse(FormatHexString(hexColor), NumberStyles.HexNumber);

public bool TryConvert(string hexColor, out int result) => int.TryParse(FormatHexString(hexColor), NumberStyles.HexNumber, null, out result);

private static string FormatHexString(string hexColor)
{
hexColor = hexColor.TrimStart('#');
if (hexColor.Length == 3)
{
hexColor = string.Concat(hexColor[0], hexColor[0], hexColor[1], hexColor[1], hexColor[2], hexColor[2]);
}
else if (hexColor.Length != 6)
{
throw new ArgumentException("Hex color must be 3 or 6 characters long.");
}

return hexColor;
}
}

0 comments on commit ddb8e32

Please sign in to comment.