Je m'attends à obtenir un rectangle de couleur, mais en obtenant le rectangle de la poubelle à la place. Jusqu'à présent, j'ai le code suivant:Comment dessiner avec Skia sur le contexte du Caire dans Gtk3
using System;
using GLib;
using SkiaSharp;
using Gtk;
namespace SkiaSharpExample {
class CCDrawingArea : DrawingArea {
protected override bool OnDrawn (Cairo.Context cr) {
using (var skSurface = SKSurface.Create (100, 100, SKColorType.N_32, SKAlphaType.Premul)) {
var canvas = skSurface.Canvas;
var paint = new SKPaint {
StrokeWidth = 4,
Color = new SKColor (255, 255, 255, 255)
};
var rect = new SKRect (10, 10, 50, 50);
canvas.DrawRect (rect, paint);
var image = skSurface.Snapshot();
Cairo.Surface surface = new Cairo.ImageSurface (
image.Encode().Data,
Cairo.Format.Argb32,
image.Width, image.Height,
4 * image.Width * image.Height);
surface.MarkDirty();
cr.SetSourceSurface (surface, 0, 0);
cr.Paint();
}
return true;
}
}
class MainClass {
public static void Main (string[] args){
ExceptionManager.UnhandledException += delegate(UnhandledExceptionArgs expArgs) {
Console.WriteLine (expArgs.ExceptionObject.ToString());
expArgs.ExitApplication = true;
};
Gtk.Application.Init();
var window = new Window ("Hello World");
window.SetDefaultSize (1024, 800);
window.SetPosition (WindowPosition.Center);
window.DeleteEvent += delegate {
Gtk.Application.Quit();
};
var darea = new CCDrawingArea();
window.Add (darea);
window.ShowAll();
Gtk.Application.Run();
}
}
}
Ce code ne fonctionnera que sur Windows où '' Cairo.Format.Argb32' et SKColorType .N_32' définit la même commande ARGB. Sur Linux et Mac 'SKColorType.N_32' est' A-B-G-R' à la place. –