Kaan EKİN
Kaan EKİN

Reputation: 65

How to render SKBitmap in Windows.Forms application?

Hi I started a new project and WinForms is new for me. I have a SKBitmap object and I don't know how can I render it.

Upvotes: 3

Views: 3358

Answers (1)

Matthew
Matthew

Reputation: 5222

There are several ways. The first thing to do is to install the SkiaSharp.Views package - a small package that contains platform specific views and utilities for converting SkiaSharp types into the current platform types:

https://www.nuget.org/packages/SkiaSharp.Views/

After installing you should get theses types:

https://developer.xamarin.com/api/namespace/SkiaSharp.Views.Desktop/

Back to the code, you can either add a SKControl and draw the bitmap on the paint event:

control.PaintSurface += (...) => {
    // draw
};

Or, you can convert the bitmap into a Windows bitmap:

var sysBitmap = skBitmap.ToBitmap();

Then, you can just assign it to a PictureBox:

pictureBox.Image = sysBitmap;

Upvotes: 7

Related Questions