Skip to content

Incompatibility with SkiaSharp v4.148.0 w/ Linux assets (ubuntu) #305

Description

@chris-rickman

Version:

https://www.nuget.org/packages/SkiaSharp/4.148.0

Call Site:

QRCodeImageBuilder.ToByteArray()

Exception:

ystem.InvalidOperationException : The version of the native libSkiaSharp library (148.0) is incompatible with this version of SkiaSharp. Supported versions of the native libSkiaSharp library are in the range [119.0, 120.0).
    at SkiaSharp.SKObject.GetOrAddObject[TSkiaObject](IntPtr handle, Boolean owns, Boolean unrefExisting, Func`3 objectFactory)
    at SkiaSharp.SKSurface.GetObject(IntPtr handle, Boolean owns, Boolean unrefExisting)
    at SkiaSharp.SKSurface.Create(SKImageInfo info, Int32 rowBytes, SKSurfaceProperties props)
    at SkiaSharp.SKSurface.Create(SKImageInfo info)
    at SkiaSharp.QrCode.Image.QRCodeImageBuilder.GenerateImage()
    at SkiaSharp.QrCode.Image.QRCodeImageBuilder.ToByteArray()
    ...

Code

    [Inject]
    private IWebHostEnvironment WebHostEnvironment { get; set; } = default!;

    [Parameter, EditorRequired]
    public string Uri { get; set; }

    [Parameter, EditorRequired]
    public int Size { get; set; }

    [Parameter, EditorRequired]
    public string IconName { get; set; }

    private string imageUrl = string.Empty;
    protected override void OnParametersSet()
    {
           QRCodeImageBuilder qrBuilder =
               new QRCodeImageBuilder(this.Uri)
                  .WithFormat(SKEncodedImageFormat.Png, quality: 100)
                  .WithErrorCorrection(ECCLevel.H) // H recommended for icons
                  .WithEciMode(EciMode.Utf8)
                  .WithQuietZone(0)
                  .WithColors(backgroundColor: SKColors.White)
                  .WithFinderPatternShape(RectangleFinderPatternShape.Default)
                  .WithModuleShape(RoundedRectangleModuleShape.Default, sizePercent: 0.92f)
                  .WithSize(this.Size.Value, this.Size.Value);
  
            if (!string.IsNullOrWhiteSpace(this.IconName))
            {
                string iconPath = this.WebHostEnvironment.GetResourcePath(this.IconName);
                if (File.Exists(iconPath))
                {
                    logo = SKBitmap.Decode(iconPath);

                    if (logo is not null)
                    {
                        IconData icon = IconData.FromImage(logo, iconSizePercent: 24, iconBorderWidth: 0);
                        qrBuilder.WithIcon(icon);
                    }
                }
            }

            this.imageUrl = $"data:image/png;base64,{Convert.ToBase64String(qrBuilder.ToByteArray())}";  // BOOM !!!
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions