SKBitmap.Decode(imageStream)返回null

时间:2019-07-08 14:57:02

标签: c# xamarin.forms skiasharp

我尝试使用skiasharp编辑作为流的图像,但是当我尝试将其转换为SKBitmap时,结果变量始终为none。我正在使用Xam.Plugin.Media来获取图像。

var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() { SaveToAlbum = false });

if (photo != null)
{
    var imageStream = photo.GetStream();
    SKBitmap bitmap = SKBitmap.Decode(imageStream);
    using (SKPaint textPaint = new SKPaint { TextSize = 48 })
    using (SKCanvas canvas = new SKCanvas(bitmap))
    {
        canvas.DrawText("test", 0, 0, textPaint);
    }

    SKImage image = SKImage.FromBitmap(bitmap);
    SKData encoded = image.Encode();
    Stream stream = encoded.AsStream();

    PhotoImage.Source = ImageSource.FromStream(() => { return stream; });
}

1 个答案:

答案 0 :(得分:0)

我获得以下内容后添加此行: var imageStream = photo.GetStream();

imageStream.seek(0, SeekOrigin.Begin);