[HttpGet] [NonUnify] public IActionResult AvatarTest() { // info 为你的画布大小 例如 with=750 hight=1024 var info = new SKImageInfo(750, 1024); // create the surface using the information var surface = SKSurface.Create(info); //载入底图 var bmp = SKBitmap.Decode("C:\\Users\\Administrator\\source\\repos\\FurionProject\\FurionProject.Web.Entry\\img\\mb.jpg"); //初始化画布 var canvas = surface.Canvas; // create a paint object so that drawing can happen at a higher resolution //创建一个绘制对象,以便绘制可以以更高的分辨率进行 using (var paint = new SKPaint()) { paint.IsAntialias = true; paint.FilterQuality = SKFilterQuality.High; canvas.DrawBitmap(bmp, info.Rect, paint); } canvas.Save(); using (var avatarImage = SKImage.FromBitmap(SKBitmap.Decode("C:\\Users\\Administrator\\source\\repos\\FurionProject\\FurionProject.Web.Entry\\img\\gz.png"))) { // 35,50是你图片的坐标 注意:不要超出画布的大小,否则无法显示 300 300是图片的大小 var rect = SKRect.Create(35, 50, 300, 300); canvas.DrawImage(avatarImage, rect); } //恢复画布状态为全图绘制状态,在画布上绘制后填写 canvas.Restore(); //最后把你画的图片保存到本地 var image = surface.Snapshot(); // encode the image as a PNG+ var data = image.Encode(SKEncodedImageFormat.Png, 100); //string filname = "ss.png"; //using (var stream = File.OpenWrite(filname)) //{ // data.SaveTo(stream); //} var arrByte= data.ToArray(); return new FileContentResult(arrByte, "image/jpeg"); }
转:.NET Core使用canvas的常用方法 SKPath SKPaint SKRect等-蒲公英云 (dandelioncloud.cn)
标签:canvas,SkiaSharp,画布,paint,var,using,FurionProject From: https://www.cnblogs.com/ucdos/p/17963128