c# - 在 Visual Studio 中使用 SkiaSharp

标签 c# visual-studio xamarin skia skiasharp

我正在研究 SkiaSharp 在未来项目中的使用,遵循 GitHub 上当前可用的文档:

https://developer.xamarin.com/guides/cross-platform/drawing/introduction/

我正在 Windows 7 上的 Visual Studio 2013 上进行开发。我尝试使用 Xamarin Android App 项目类型,但它需要 SkiaSharp 包中 DllImportAttribute 的商业许可证。

我想知道是否可以选择一个 C# Visual Studio 项目来显示 SkiaSharp Canvas ,如果可以,我该怎么做?

最佳答案

评论上的链接目前已损坏。由于“samples”文件夹以后可能会再次更改路径,有需要的可以从https://github.com/mono/SkiaSharp开始探索。页面。

有关使用 SkiaSharp 的更多信息,请访问 API documentation online在这篇关于使用 skia sharp 绘图的文章中

这里有一些例子,对于需要实用快速入门的人来说如何使用它:

获取 SKCanvas

using (var surface = SKSurface.Create (width: 640, height: 480, SKColorType.N_32, SKAlphaType.Premul)) {
SKCanvas myCanvas = surface.Canvas;

// Your drawing code goes here.
}

绘制文字

// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);

// set up drawing tools
using (var paint = new SKPaint ()) {
  paint.TextSize = 64.0f;
  paint.IsAntialias = true;
  paint.Color = new SKColor (0x42, 0x81, 0xA4);
  paint.IsStroke = false;

  // draw the text
  canvas.DrawText ("Skia", 0.0f, 64.0f, paint);
}

绘制位图

Stream fileStream = File.OpenRead ("MyImage.png");

// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);

// decode the bitmap from the stream
using (var stream = new SKManagedStream(fileStream))
using (var bitmap = SKBitmap.Decode(stream))
using (var paint = new SKPaint()) {
  canvas.DrawBitmap(bitmap, SKRect.Create(Width, Height), paint);
}

使用图像滤镜绘图

Stream fileStream = File.OpenRead ("MyImage.png"); // open a stream to an image file

// clear the canvas / fill with white
canvas.DrawColor (SKColors.White);

// decode the bitmap from the stream
using (var stream = new SKManagedStream(fileStream))
using (var bitmap = SKBitmap.Decode(stream))
using (var paint = new SKPaint()) {
  // create the image filter
  using (var filter = SKImageFilter.CreateBlur(5, 5)) {
    paint.ImageFilter = filter;

    // draw the bitmap through the filter
    canvas.DrawBitmap(bitmap, SKRect.Create(width, height), paint);
  }
}

关于c# - 在 Visual Studio 中使用 SkiaSharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719258/

相关文章:

c++ - 从文件中删除重复的反向行时出现问题

android - Visual Studio 2015 中的 "No devices available"

c# - 自定义呈现器 DatePicker CountDownTimer 不会在 Xamarin 表单中更改值

ios - 导航 Controller 为空

c# - ASP.net MVC 数据表 Ajax 错误

c# - 如何从现有的 excel 文件中读取单元格值

vb.net - VS2008 "must implement"假错误?

c# - 如何在 Zedgraph 中绘制一个在鼠标不移动时持续存在的扩展十字线光标?

c# - Azure AD 从身份验证结果对象获取访问 token

c# - 如何将多个 list 文件嵌入/合并到 C# 应用程序中?