Created
September 25, 2022 07:24
-
-
Save guitarrapc/bc11f8d7c2ae3ce4e481aa391b5e0c88 to your computer and use it in GitHub Desktop.
Try reproduce https://github.com/guitarrapc/SkiaSharp.QrCode/issues/54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.2" /> | |
<PackageReference Include="SkiaSharp.QrCode" Version="0.6.0" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Update="Untitled.png"> | |
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |
</None> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SkiaSharp.QrCode.Models; | |
using SkiaSharp; | |
using SkiaSharp.QrCode; | |
var url = "https://example.com"; | |
var byteIcon = File.ReadAllBytes(@"Untitled.png"); | |
var icon = new IconData | |
{ | |
Icon = SKBitmap.Decode(byteIcon), | |
IconSizePercent = 10, | |
}; | |
using var generator = new QRCodeGenerator(); | |
var qr = generator.CreateQrCode(url, ECCLevel.L); | |
var info = new SKImageInfo(512, 512); | |
using var surface = SKSurface.Create(info); | |
var canvas = surface.Canvas; | |
canvas.Render(qr, info.Width, info.Height, SKColor.Parse("ffffff"), SKColor.Parse("000000"), icon); | |
using var image = surface.Snapshot(); | |
using var data = image.Encode(SKEncodedImageFormat.Png, 100); | |
data.SaveTo(new FileStream($"../Generated_{System.Runtime.InteropServices.RuntimeInformation.OSDescription}.png", FileMode.CreateNew)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Untitled.png
WSL2 Ubuntu 22.04 result
Windows 11 result