Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Apr 24, 2024
1 parent 2eac6ad commit 70b2855
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions QRCoder/Base64QRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,22 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
}

#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
if (
#if NET6_0_OR_GREATER
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
#else
true
#endif
)
{
var qr = new QRCode(QrCodeData);
var base64 = string.Empty;
using (Bitmap bmp = qr.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones))
{
base64 = BitmapToBase64(bmp, imgType);
}
return base64;
}
else
#pragma warning disable CA1416 // Validate platform compatibility
var qr = new QRCode(QrCodeData);
var base64 = string.Empty;
using (Bitmap bmp = qr.GetGraphic(pixelsPerModule, darkColor, lightColor, drawQuietZones))
{
throw new PlatformNotSupportedException("The specified image type is not supported on this platform.");
base64 = BitmapToBase64(bmp, imgType);
}
return base64;
#pragma warning restore CA1416 // Validate platform compatibility
#else
throw new PlatformNotSupportedException("The specified image type is not supported on this platform.");
throw new PlatformNotSupportedException("Only the PNG image type is supported on this platform.");
#endif
}

#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
#if NET6_0_WINDOWS
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Bitmap icon, int iconSizePercent = 15, int iconBorderWidth = 6, bool drawQuietZones = true, ImageType imgType = ImageType.Png)
Expand All @@ -105,7 +94,7 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
#endif

#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
#if NET6_0_WINDOWS
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
private string BitmapToBase64(Bitmap bmp, ImageType imgType)
Expand Down Expand Up @@ -137,11 +126,11 @@ private string BitmapToBase64(Bitmap bmp, ImageType imgType)

public enum ImageType
{
#if NET6_0_WINDOWS
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
Gif,
#if NET6_0_WINDOWS
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
Jpeg,
Expand Down

0 comments on commit 70b2855

Please sign in to comment.