gpt4 book ai didi

c# - 缩放 SKImage (SkiaSharp) 的最快方法

转载 作者:行者123 更新时间:2023-11-30 18:15:24 30 4
gpt4 key购买 nike

我正在寻找调整 SKImage 大小的最快方法。不幸的是,我找到了一些例子。

我问这个是因为如果我并行执行这些函数(在我的例子中大约有 60 个线程),每个缩放函数的执行时间会增加多达 20 倍。

我尝试了以下方法,性能看起来非常相似,还有更好的方法吗?

方法一:

SKImage src = (...);
SKImageInfo info = new SKImageInfo(width, height, SKColorType.Bgra8888);
SKImage output = SKImage.Create(info);
src.ScalePixels(output.PeekPixels(), SKFilterQuality.None);

方法二:

SKImage src = (...);
SKImage output;
float resizeFactorX = (float)width / (float)Src.Width;
float resizeFactorY = (float)height / (float)Src.Height;

using (SKSurface surface = SKSurface.Create((int)(Src.Width *
resizeFactorX), (int)(Src.Height * resizeFactorY),
SKColorType.Bgra8888, SKAlphaType.Opaque))
{
surface.Canvas.SetMatrix(SKMatrix.MakeScale(resizeFactorX, resizeFactorY));
surface.Canvas.DrawImage(Src, 0, 0);
surface.Canvas.Flush();
output = surface.Snapshot();
}

最佳答案

这是我使用的代码。另一个想法是确保将您的 SKImage 对象包装在 using 中,以确保它们被快速处理。我不确定这是否会导致每次迭代速度变慢。

using (var surface = SKSurface.Create(resizedWidth, resizedHeight,
SKImageInfo.PlatformColorType, SKAlphaType.Premul))
using (var paint = new SKPaint())
{
// high quality with antialiasing
paint.IsAntialias = true;
paint.FilterQuality = SKFilterQuality.High;

// draw the bitmap to fill the surface
surface.Canvas.DrawImage(srcImg, new SKRectI(0, 0, resizedWidth, resizedHeight),
paint);
surface.Canvas.Flush();

using (var newImg = surface.Snapshot())
{
// do something with newImg
}
}

关于c# - 缩放 SKImage (SkiaSharp) 的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48422724/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com