I have a question. I have a skiasharp canvas with a few bitmaps. Now I want to export the canvas with the bitmaps to an Image, but I have no idea how to do that, or if that is possible.
Can someone help me?
I have a question. I have a skiasharp canvas with a few bitmaps. Now I want to export the canvas with the bitmaps to an Image, but I have no idea how to do that, or if that is possible.
Can someone help me?
You are probably looking to take a Snapshot of the Surface.
using (var image = surface.Snapshot())
using (var data = image.Encode(SKEncodedImageFormat.Png, 80))
using (var stream = File.OpenWrite(Path.Combine(FolderPath, "1.png")))
{
// save the data to a stream
data.SaveTo(stream);
}
This is very similar to MShah's answer, but just from a snapshot of the surface instead, given that surface
is a reference to your Skia Surface.
To convert the bitmap to image:
using (var image = SKImage.FromBitmap(yourBitmap))
using (var data = image.Encode(SKEncodedImageFormat.Png, 80))
{
// save the data to a stream
using (var stream = File.OpenWrite(Path.Combine(FolderPath, "1.png")))
{
data.SaveTo(stream);
}
}
Edit:
To convert canvas to png:
SKImage mainCanvasImage = surface.Snapshot();
SKBitmap TempTIFbitmap1 = SKBitmap.Decode(mainCanvasImage.Encode())
Use the above code from point 1 to save this.
hope this will resolve your issue.