问题描述
我尝试从我在 Xamarin Foms 中的应用程序中捕获的照片中获得多边形裁剪。 我使用 SkiaSharp 。所以第一步是好的,我像这样从我的 EdgeCroppingView 得到一个画布
所以现在我想在全屏中裁剪选择并“调整大小”,只有选择(围绕猫),我有这个:
The selected skpath (the borders) are correctly "resizing" but not the inside content(the cat's area) : i would like to strech this area ...
有什么想法吗?
private void OnCanvasViewPaintSurface(object sender,SKPaintSurfaceEventArgs e)
{
SKImageInfo info = e.Info;
SKSurface surface = e.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
if (_pathToClip != null)
{
SKRect rectSource;
_pathToClip.GetTightBounds(out rectSource);
e.Surface.Canvas.Clear();
SKRect canvasRect = SKRect.Create(e.Info.Size);
//I need to find the size of the path
SKRect pathRect = _pathToClip.TightBounds;
//I want to find the largest rectangle that can fit on my canvas maintaining the path's aspect ratio
//SkiaSharp added a builtin method for this based on code from me
SKRect drawPathRect = canvasRect.AspectFit(pathRect.Size);
//Now I need to transform the path to draw within the drawPathRect
//First translate original path to its own origin
SKMatrix firstTranslateM = SKMatrix.CreateTranslation(-pathRect.Left,-pathRect.Top);
//Next handle scaling. Since I maintained aspect ratio,I should be able to use either
//width or height to figure out scaling factor
float scalingFactor = drawPathRect.Width / pathRect.Width;
SKMatrix scaleM = SKMatrix.CreateScale(scalingFactor,scalingFactor);
//Last I need to handle translation so path is centered on canvas
SKMatrix secondTranslateM = SKMatrix.CreateTranslation(drawPathRect.Left,drawPathRect.Top);
//Now combine the translation,scaling,and translation into a single matrix by matrix multiplication/concatentation
SKMatrix transformM = SKMatrix.CreateIdentity();
SKMatrix.PostConcat(ref transformM,firstTranslateM);
SKMatrix.PostConcat(ref transformM,scaleM);
SKMatrix.PostConcat(ref transformM,secondTranslateM);
//Now apply the transform to the path
_pathToClip.Transform(transformM);
canvas.ClipPath(_pathToClip);
using (var paint = new SKPaint())
{
paint.Style = SKPaintStyle.stroke;
paint.Color = SKColors.magenta;
paint.strokeWidth = 5;
canvas.DrawPath(_pathToClip,paint);
canvas.DrawBitmap(Bitmap,info.Rect,BitmapStretch.UniformToFill );
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)