System.ArgumentNullException: 'Value cannot be null. Parameter name: input' Xamarin?



我有一个问题与Xamarin在sKSVG.Load(stream):

System.ArgumentNullException: 'Value cannot be null. Parameter name: input'
using(Stream stream = typeof(SVGImage).GetTypeInfo().Assembly.GetManifestResourceStream(assembly.Name + ".Images."+ Source))
{
SkiaSharp.Extended.Svg.SKSvg sKSVG = new SkiaSharp.Extended.Svg.SKSvg();
sKSVG.Load(stream);
SKImageInfo imageInfo = e.Info;
sKCanvas.Translate(imageInfo.Width / 2f, imageInfo.Height / 2f);
SKRect rectBounds = sKSVG.ViewBox;
float xRatio = imageInfo.Width / rectBounds.Width;
float yRatio = imageInfo.Height / rectBounds.Height;
float minRatio = Math.Min(xRatio, yRatio);
sKCanvas.Scale(minRatio);
sKCanvas.Translate(-rectBounds.MidX, -rectBounds.MidY);
sKCanvas.DrawPicture(sKSVG.Picture);
}

我想你可能忘记为图像资源设置Buidl Action了。

您可以将其BuildAction设置为EmbeddedResource

,那么你可以得到这样的流:

var type = typeof(MainPage).GetTypeInfo();
var assembly = type.Assembly;
using (Stream stream = assembly.GetManifestResourceStream(assembly.GetName().Name+ ".Images." + "your svg.svg"))
{
SKSvg sKSvg = new SKSvg();
sKSvg.Load(stream);
...
}

参考https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/bitmaps#loading-a-bitmap-resource

相关内容

  • 没有找到相关文章

最新更新