首页 文章

在Visual Studio中使用SkiaSharp

提问于
浏览
2

我正在研究将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画布,如果是这样,我该怎么做?

1 回答

  • 6

    评论上的链接目前已被删除 . 由于文件夹"samples"可能会在将来再次更改路径,无论谁需要都可以从https://github.com/mono/SkiaSharp页面开始探索 .

    有关使用SkiaSharp的更多信息,请参阅API documentation online以及本文中有关使用skia sharp绘图的信息

    对于谁需要一个实用的快速入门,如何在这里使用它一些例子:

    Getting an SKCanvas

    using (var surface = SKSurface.Create (width: 640, height: 480, SKColorType.N_32, SKAlphaType.Premul)) {
    SKCanvas myCanvas = surface.Canvas;
    
    // Your drawing code goes here.
    }
    

    Drawing Text

    // 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);
    }
    

    Drawing Bitmaps

    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);
    }
    

    Drawing with Image Filters

    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);
      }
    }
    

相关问题