簡體   English   中英

從控制台應用程序使用 OpenGL/Vulkan 后端的 SkiaSharp 繪圖

[英]SkiaSharp drawing with OpenGL/Vulkan backend from console application

我想使用 SkiaSharp 使用 GPU 加速(使用 OpenGL 或 Vulkan)繪制一些東西並稍后保存圖像。 無需在應用程序的任何位置顯示圖像,因為它是針對 Windows 和 Linux 的控制台應用程序。

我已經嘗試了以下代碼,有各種變化,但沒有任何效果(在var surface = SKSurface.Create(context, false, info);引發異常,因為glInterfacecontextnull

有人可以給我一個提示嗎?

var glInterface = GRGlInterface.Create();
var context = GRContext.CreateGl(glInterface);

var info = new SKImageInfo(256, 256);
var surface = SKSurface.Create(context, false, info);
var canvas = surface.Canvas;

最后,如果能夠調用SKBitmap.SetPixels(IntPrt)或類似的東西來將生成的 bitmap 緩沖區設置到特定位置,那就太好了。

解決方案是您需要先手動創建 OpenGL 上下文。 查看https://github.com/mono/SkiaSharp/blob/master/tests/Tests/GRContextTest.cs了解實現細節。

要復制渲染的像素緩沖區,您可以使用SKSurface.ReadPixels

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM