- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找调整 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/
我试图找出由字节数组加载到 SKBitmap 的图像的格式。我只想知道它是 JPEG 还是 PNG 等。 // Was the decoding done by a JPEG decoder or P
我正在使用 SkiaSharp 将标签打印为 PDF(和其他内容)。 PDF 的每一页都可以有多个行和列。我需要将每个标签剪裁到正确的大小,这样它就不会破坏相邻的标签。 为了测试,每个标签都有一个延伸
我正在尝试使用以下代码在 SkiaSharp Canvas View 上绘制圆弧。 path3.ArcTo(new SKPoint(0, h/2), 1.57f, SKPathArcSize.Larg
我正在尝试使用以下代码在 SkiaSharp Canvas View 上绘制圆弧。 path3.ArcTo(new SKPoint(0, h/2), 1.57f, SKPathArcSize.Larg
我正在尝试创建一个 Remote ,但不确定如何使用如下图所示的圆弧绘制路径。 我考虑过使用 SKPath.DrawArc 来绘制那个按钮。当用户点击屏幕时,我可以比较触摸点在 SKPath 内部。目
我想镜像一个位图,这样我就可以让一个图像和它的镜像彼此相邻。我正在使用 SkiaSharp,我的位图是 SKBitmap,我正在 Canvas 上绘制它们。 canvas.Translate( -im
我正在尝试使用 Xamarin SkiaSharp 实现流畅的动画。核心问题是调用 canvasView.InvalidateSurface(); 之间的时间。并点击 mathod OnCanvasV
我正在使用 SkiaSharp 对一些图像进行切片,一些图片没有覆盖整个位图,看起来有些图片上有随机噪声。 最简单的复制方法就是创建新的空位图并将它们保存在一个循环中。像这样: // imgSize
当文本在前缀或后缀中包含空格时,SkiaSharp 不考虑空格。它仅返回文本宽度并忽略空格。我正在使用以下代码片段来测量字符串。 SKPaint paint = new SKPaint
如何在 SkiaSharp 中绘制旋转文本。 目前我正在旋转 SKCanvas,绘制文本,然后将其旋转回来。但我认为可能有一种更有效的方法来做到这一点。 canvas.RotateDegrees(45
我尝试使用 SkiaSharp 将照片旋转到 90 度,代码如下: public SKBitmap Rotate() { var bitmap = SKBitmap.D
目前,SkiaSharp 不支持 tiff 图像。 (它支持 jpg、gif、bmp、png 和其他一些格式。) 如何将 tiff 图像转换为 SKBitmap 对象? 一个想法:也许有一种有效的方法
如何在 iOS 中使用 Skia Sharp 添加矩形或任何形状并将填充颜色和描边颜色应用于该对象 最佳答案 要同时绘制填充和描边,您必须执行两个绘制操作: // the rectangle var
使用 GDI 时,我能够设置 Pen::Alignment to Inset , 它在路径的内侧绘制了笔划。 SkiaSharp 是否有类似的概念?我已经搜索了所有 SKPaint 文档,但没有找到我
我从未在编程中使用过 SkiaSharp 或处理过 SVG 和旋转点。我对矩阵的工作原理感到困惑;研究时看起来很复杂。我知道我可以将我的 pivotX/Y 点移动到中心,这样我就可以说我想将图像旋转
我正在尝试绘制和填充一个三角形。我提到了一个 android - 问题 How to draw filled triangle on android Canvas并做了以下事情。它绘制了三角形,但没有
我知道 SkiaSharp Canvas 可以放置在 Xamarin 应用程序的 Grid 中。这是一些示例(工作)代码: xmlns:skia="clr-namespace:SkiaSharp.Vi
有人知道如何在 SkiaSharp.Views.UWP 命名空间中使用 SKXamlCanvas 吗? 我找到了关于 SkiaSharp.Views.Forms 和 SKCanvasView 的信息。
我知道 SkiaSharp Canvas 可以放置在 Xamarin 应用程序的 Grid 中。这是一些示例(工作)代码: xmlns:skia="clr-namespace:SkiaSharp.Vi
有人知道如何在 SkiaSharp.Views.UWP 命名空间中使用 SKXamlCanvas 吗? 我找到了关于 SkiaSharp.Views.Forms 和 SKCanvasView 的信息。
我是一名优秀的程序员,十分优秀!