Forum Xamarin.Forms

SKCanvasView to Image (Png, Jpeg)

Hi Guys!

Is Possible generate a image file of an SKCanvasView with multiple bitmaps?

Best Answer

  • seanydaseanyda GBMember ✭✭✭✭✭
    Accepted Answer

    Yeah sure!

    var info = new SKImageInfo((int)canvasView.CanvasSize.Width, (int)canvasView.CanvasSize.Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                    var newSurface = SKSurface.Create(info);
                    var canvas = newSurface.Canvas;
    
                    // DRAW YOUR BITMAPS
                    canvas.DrawBitmap(savedBitmap, 0, 0);
    
                    var snap = newSurface.Snapshot();
                    var jpgImage = snap.Encode(SKEncodedImageFormat.Jpeg, 80); // SKEndedImageFormat is an enum, You can switch between PNG and JPEG.
    

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭
    Accepted Answer

    Yeah sure!

    var info = new SKImageInfo((int)canvasView.CanvasSize.Width, (int)canvasView.CanvasSize.Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                    var newSurface = SKSurface.Create(info);
                    var canvas = newSurface.Canvas;
    
                    // DRAW YOUR BITMAPS
                    canvas.DrawBitmap(savedBitmap, 0, 0);
    
                    var snap = newSurface.Snapshot();
                    var jpgImage = snap.Encode(SKEncodedImageFormat.Jpeg, 80); // SKEndedImageFormat is an enum, You can switch between PNG and JPEG.
    
Sign In or Register to comment.