Microsoft.Maui.Graphics BitmapExportContext 使用ICanvas时DrawImage无法绘制图像的问题
原:
using FileStream fs = File.OpenRead("E:\\ImageSlicerOutput\\B0BDWKTIQ.png"); using Microsoft.Maui.Graphics.IImage source = PlatformImage.FromStream(fs, ImageFormat.Png); using SkiaBitmapExportContext skiaBitmapExportContext = new((int)source.Width,(int)source.Height,1); skiaBitmapExportContext.Canvas.DrawImage(source,0,0,source.Width,source.Height); skiaBitmapExportContext.WriteToFile("E:\\ImageSlicerOutput\\BOB.png");
解决方法:
using FileStream fs = File.OpenRead("E:\\ImageSlicerOutput\\B0BDWKTIQ.png"); Microsoft.Maui.Graphics.IImage source = PlatformImage.FromStream(fs, ImageFormat.Png); if (source is not SkiaImage && source is PlatformImage platformImage) { Microsoft.Maui.Graphics.IImage image = SkiaImage.FromStream(platformImage.AsStream(), ImageFormat.Png); source.Dispose(); source = image; } using SkiaBitmapExportContext skiaBitmapExportContext = new((int)source.Width,(int)source.Height,1); skiaBitmapExportContext.Canvas.DrawImage(source,0,0,source.Width,source.Height); skiaBitmapExportContext.WriteToFile("E:\\ImageSlicerOutput\\BOB.png");
必须是Microsoft.Maui.Graphics.Skia.SkiaImage
from:https://github.com/dotnet/maui/issues/27136
浙公网安备 33010602011771号