public static void RenderSvg(SKCanvas canvas, SkiaSharp.Extended.Svg.SKSvg svg, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Top, float opacity = 1f, float scale = 1f) { canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: degrees or radians? canvas.Scale(scale, scale); var halfWidth = svg.CanvasSize.Width / 2; var halfHeight = svg.CanvasSize.Height / 2; // 0/0 are assumed at center of image, but Svg has 0/0 at left top position canvas.Translate(-halfWidth + offsetX, -halfHeight - offsetY); var rect = new SKRect(-halfWidth, -halfHeight, +halfWidth, +halfHeight); //var color = new SKColor(255, 255, 255, (byte)(255 * opacity)); //var paint = new SKPaint { Color = color, FilterQuality = SKFilterQuality.High }; canvas.DrawPicture(svg.Picture, null); canvas.Restore(); }
public static void Draw(SKCanvas canvas, SKImage bitmap, float x, float y, float rotation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center, float opacity = 1f, float scale = 1f) { canvas.Save(); canvas.Translate(x, y); if (rotation != 0) { canvas.RotateDegrees(rotation, 0, 0); } canvas.Scale(scale, scale); var width = bitmap.Width; var height = bitmap.Height; x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, width); y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, height); var halfWidth = width >> 1; var halfHeight = height >> 1; var rect = new SKRect(x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight); Draw(canvas, bitmap, rect, opacity); canvas.Restore(); }
public static void RenderBitmap(SKCanvas canvas, SKImage bitmap, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center, float opacity = 1f, float scale = 1f) { canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: degrees or radians? canvas.Scale(scale, scale); x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, bitmap.Width); y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, bitmap.Height); var halfWidth = bitmap.Width / 2; var halfHeight = bitmap.Height / 2; var rect = new SKRect(x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight); RenderBitmap(canvas, bitmap, rect, opacity); canvas.Restore(); }
public static void RenderTexture(TextureInfo textureInfo, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center, float opacity = 1f, float scale = 1f) { GL.Enable(All.Texture2D); GL.BindTexture(All.Texture2D, textureInfo.TextureId); GL.PushMatrix(); GL.Translate(x, y, 0f); GL.Rotate(orientation, 0, 0, 1); GL.Scale(scale, scale, 1); x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, textureInfo.Width); y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, textureInfo.Height); var halfWidth = textureInfo.Width / 2; var halfHeight = textureInfo.Height / 2; var vertextArray = new[] { x - halfWidth, y - halfHeight, x + halfWidth, y - halfHeight, x + halfWidth, y + halfHeight, x - halfWidth, y + halfHeight }; RenderTextureWithoutBinding(textureInfo.TextureId, vertextArray, opacity); GL.PopMatrix(); GL.BindTexture(All.Texture2D, 0); GL.Disable(All.Texture2D); }
public static void Draw(SKCanvas canvas, SkiaSharp.Extended.Svg.SKSvg svg, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Top, float opacity = 1f, float scale = 1f) { // todo: I assume we also need to apply opacity. // todo: It seems horizontalAlignment and verticalAlignment would make sense too. Is this similar to Anchor? canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: degrees or radians? canvas.Scale(scale, scale); var halfWidth = svg.CanvasSize.Width / 2; var halfHeight = svg.CanvasSize.Height / 2; // 0/0 are assumed at center of image, but Svg has 0/0 at left top position canvas.Translate(-halfWidth + offsetX, -halfHeight - offsetY); canvas.DrawPicture(svg.Picture, new SKPaint() { IsAntialias = true }); canvas.Restore(); }
private static float DetermineVerticalAlignmentCorrection( LabelStyle.VerticalAlignmentEnum verticalAlignment, float height) { if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Top) { return(-height / 2); } if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Bottom) { return(height / 2); } return(0.0f); // center }
private static int DetermineVerticalAlignmentCorrection( LabelStyle.VerticalAlignmentEnum verticalAlignment, int height) { if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Top) { return(-(height >> 1)); } if (verticalAlignment == LabelStyle.VerticalAlignmentEnum.Bottom) { return(height >> 1); } return(0); // center }
private static float CalcVerticalAlignment(LabelStyle.VerticalAlignmentEnum verticalAligment) { if (verticalAligment == LabelStyle.VerticalAlignmentEnum.Center) { return(0.5f); } if (verticalAligment == LabelStyle.VerticalAlignmentEnum.Top) { return(0f); } if (verticalAligment == LabelStyle.VerticalAlignmentEnum.Bottom) { return(1f); } throw new ArgumentException(); }
public static void RenderSvg(SKCanvas canvas, SkiaSharp.Extended.Svg.SKSvg svg, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Top, float opacity = 1f, float scale = 1f) { canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: degrees or radians? canvas.Scale(scale, scale); var halfWidth = svg.CanvasSize.Width / 2; var halfHeight = svg.CanvasSize.Height / 2; // 0/0 are assumed at center of image, but Svg has 0/0 at left top position canvas.Translate(-halfWidth + offsetX, -halfHeight - offsetY); canvas.DrawPicture(svg.Picture); canvas.Restore(); }
public static void Draw(SKCanvas canvas, SKSvg svg, float x, float y, float orientation = 0, float offsetX = 0, float offsetY = 0, LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left, LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Top, float opacity = 1f, float scale = 1f) { // todo: I assume we also need to apply opacity. // todo: It seems horizontalAlignment and verticalAlignment would make sense too. Is this similar to Anchor? canvas.Save(); canvas.Translate(x, y); canvas.RotateDegrees(orientation, 0, 0); // todo: degrees or radians? canvas.Scale(scale, scale); var halfWidth = svg.Picture.CullRect.Width / 2; var halfHeight = svg.Picture.CullRect.Height / 2; // 0/0 are assumed at center of image, but Svg has 0/0 at left top position canvas.Translate(-halfWidth + offsetX, -halfHeight - offsetY); var alpha = Convert.ToByte(255 * opacity); var transparency = SKColors.White.WithAlpha(alpha); using (var cf = SKColorFilter.CreateBlendMode(transparency, SKBlendMode.DstIn)) { canvas.DrawPicture(svg.Picture, new SKPaint() { IsAntialias = true, ColorFilter = cf, }); } canvas.Restore(); }