本文整理汇总了C#中SkiaSharp.SKPaint类的典型用法代码示例。如果您正苦于以下问题:C# SKPaint类的具体用法?C# SKPaint怎么用?C# SKPaint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SKPaint类属于SkiaSharp命名空间,在下文中一共展示了SKPaint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderRaster
public static void RenderRaster(SKCanvas canvas, SKBitmap bitmap, SKRect rect, float opacity = 1f)
{
// Better for quality. Helps to compare to WPF
var color = new SKColor(255, 255, 255, (byte)(255 * opacity));
var paint = new SKPaint { Color = color, FilterQuality = SKFilterQuality.High };
canvas.DrawBitmap(bitmap, rect, paint);
// Better for performance:
canvas.DrawBitmap(bitmap, rect);
}
示例2: Draw
public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IGeometry geometry)
{
var lineString = ((LineString) geometry).Vertices;
float lineWidth = 1;
var lineColor = new Color();
var vectorStyle = style as VectorStyle;
if (vectorStyle != null)
{
lineWidth = (float) vectorStyle.Line.Width;
lineColor = vectorStyle.Line.Color;
}
var line = WorldToScreen(viewport, lineString);
var path = ToSkia(line);
using (var paint = new SKPaint())
{
paint.IsStroke = true;
paint.StrokeWidth = lineWidth;
paint.Color = lineColor.ToSkia();
paint.StrokeJoin = SKStrokeJoin.Round;
canvas.DrawPath(path, paint);
}
}
示例3: FormattedTextImpl
public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle,
TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping)
{
_text = text ?? string.Empty;
// Replace 0 characters with zero-width spaces (200B)
_text = _text.Replace((char)0, (char)0x200B);
var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight);
_paint = new SKPaint();
//currently Skia does not measure properly with Utf8 !!!
//Paint.TextEncoding = SKTextEncoding.Utf8;
_paint.TextEncoding = SKTextEncoding.Utf16;
_paint.IsStroke = false;
_paint.IsAntialias = true;
_paint.LcdRenderText = true;
_paint.SubpixelText = true;
_paint.Typeface = typeface;
_paint.TextSize = (float)fontSize;
_paint.TextAlign = textAlignment.ToSKTextAlign();
_wrapping = wrapping;
Rebuild();
}
示例4: Draw
public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IGeometry geometry)
{
var polygon = (Polygon)geometry;
float lineWidth = 1;
var lineColor = Color.Black; // default
var fillColor = Color.Gray; // default
var vectorStyle = style as VectorStyle;
if (vectorStyle != null)
{
lineWidth = (float) vectorStyle.Outline.Width;
lineColor = vectorStyle.Outline.Color;
fillColor = vectorStyle.Fill?.Color;
}
using (var path = ToSkia(viewport, polygon))
{
using (var paint = new SKPaint())
{
paint.IsAntialias = true;
paint.StrokeWidth = lineWidth;
paint.Style = SKPaintStyle.Fill;
paint.Color = fillColor.ToSkia();
canvas.DrawPath(path, paint);
paint.Style = SKPaintStyle.Stroke;
paint.Color = lineColor.ToSkia();
canvas.DrawPath(path, paint);
}
}
}
示例5: SkiaCanvasPainter
//-----------------------
public SkiaCanvasPainter(int w, int h)
{
_fill = new SKPaint();
_stroke = new SKPaint();
_stroke.IsStroke = true;
_width = w;
_height = h;
}
示例6: DrawImage
public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect)
{
var impl = (BitmapImpl)source.PlatformImpl;
var s = sourceRect.ToSKRect();
var d = destRect.ToSKRect();
using (var paint = new SKPaint()
{ Color = new SKColor(255, 255, 255, (byte)(255 * opacity)) })
{
Canvas.DrawBitmap(impl.Bitmap, s, d, paint);
}
}
示例7: CreateBackgroundImage
public SKImage CreateBackgroundImage ()
{
SKPaint paint = null;
SKPath path = null;
try
{
var height = (int)Bounds.Height;
var width = (int)Bounds.Width;
using (var surface = SKSurface.Create (width, height, SKColorType.N_32, SKAlphaType.Premul))
{
var canvas = surface.Canvas;
//canvas.Clear (SKColors.Beige);
paint = new SKPaint
{
Color = SKColors.DarkBlue,
IsStroke = true,
StrokeWidth = 1,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
//path = new SKPath ();
//path.MoveTo (0f, 0f);
//path.LineTo (width, height);
//path.Close ();
//canvas.DrawPath (path, paint);
//DrawArc (canvas, paint, 0, 90);
var start = -90;
var end = 0;
//DrawCircle (canvas, paint, width / 2, height / 2, width / 2 - 4);
DrawArcFromTo (canvas, paint, width / 2, height / 2, width / 2 - 4, start, end);
DrawArcFromTo (canvas, paint, width / 2, height / 2, (int)((width / 2 - 4) * 0.8), start, end);
return surface.Snapshot ();
}
}
finally
{
if (paint != null)
paint.Dispose ();
if (path != null)
path.Dispose ();
}
}
示例8: CreateLabelAsBitmap
private static SKBitmap CreateLabelAsBitmap(LabelStyle style, string text, SKPaint paint)
{
var rect = new SKRect();
paint.MeasureText(text, ref rect);
var backRect = new SKRect(0, 0, rect.Width + 6, rect.Height + 6);
var bitmap = new SKBitmap((int)backRect.Width, (int)backRect.Height);
using (var target = new SKCanvas(bitmap))
{
target.Clear();
DrawBackground(style, backRect, target);
target.DrawText(text, -rect.Left + 3, -rect.Top +3, paint);
return bitmap;
}
}
示例9: Draw
protected override void Draw(SKCanvas canvas, int width, int height)
{
float time = _frame / (LengthSec * Fps);
using (var paint = new SKPaint())
{
paint.Color = Foreground.ToSkia();
paint.StrokeWidth = (float)StrokeWidth;
paint.IsAntialias = true;
paint.IsStroke = true;
for (int a = 0; a < 3; ++a)
{
var matrix = SKMatrix.MakeRotation(2 * (float)Math.PI * time / 6 + 2 * (float)Math.PI * a / 3);
matrix.TransX = width / 2f;
matrix.TransY = height / 2f;
canvas.SetMatrix(matrix);
const int n = 12;
const int sp = 39;
for (int i = -n; i <= n; ++i)
{
float y = (float)(i * sp * Math.Pow(2, time));
float tt = (float)Math.Min(1, Math.Max(0, 1.09 * time - 0.00275 * Math.Abs(y) + 0.075));
float x;
if (i % 2 == 0)
x = width;
else
x = width * tt;
if (x > 0)
canvas.DrawLine(-x, y, x, y, paint);
}
}
}
++_frame;
if (_frame > LengthSec * Fps)
_frame = 0;
}
示例10: CreateGraphicsFromNativeHdc
void CreateGraphicsFromNativeHdc(int width, int height)
{
skBitmap = new SKBitmap(width, height);
skCanvas = new SKCanvas(skBitmap);
//
stroke = new SKPaint();
stroke.IsStroke = true;
//
fill = new SKPaint();
fill.IsStroke = false;
//
textFill = new SKPaint();
textFill.IsAntialias = true;
//---------------------------------------
//---------------------------------------
this.CurrentFont = new RequestFont("tahoma", 14);
this.CurrentTextColor = Color.Black;
//---------------------------------------
}
示例11: DrawPoints
public void DrawPoints(SKPointMode mode, SKPoint [] points, SKPaint paint)
{
if (paint == null)
throw new ArgumentNullException (nameof (paint));
if (points == null)
throw new ArgumentNullException (nameof (points));
SkiaApi.sk_canvas_draw_points (Handle, mode, (IntPtr)points.Length, points, paint.Handle);
}
示例12: ApplyTo
public IDisposable ApplyTo(SKPaint paint)
{
var state = new PaintState(paint, paint.Color, paint.Shader);
paint.Color = Paint.Color;
paint.Shader = Paint.Shader;
return state;
}
示例13: PaintWrapper
public PaintWrapper(SKPaint paint)
{
Paint = paint;
_disposable1 = null;
}
示例14: DrawText
public void DrawText(string text, SKPath path, float hOffset, float vOffset, SKPaint paint)
{
if (text == null)
throw new ArgumentNullException ("text");
if (paint == null)
throw new ArgumentNullException (nameof (paint));
if (paint == null)
throw new ArgumentNullException (nameof (paint));
var bytes = Util.GetEncodedText (text, paint.TextEncoding);
SkiaApi.sk_canvas_draw_text_on_path (Handle, bytes, bytes.Length, path.Handle, hOffset, vOffset, paint.Handle);
}
示例15: DrawLine
public void DrawLine(float x0, float y0, float x1, float y1, SKPaint paint)
{
if (paint == null)
throw new ArgumentNullException (nameof (paint));
SkiaApi.sk_canvas_draw_line (Handle, x0, y0, x1, y1, paint.Handle);
}