Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Resizing a skiasharp canvas in order to print to a Pdf

$
0
0

Trying to make use of skiasharp implementation in a xamarin UWP-only project, which requires a bit of scaling and printing to a pdf with the end result. So far, results have been encouraging however printing to Pdf by means of cropping the bitmap failed miserably. This is the current implementation, would hope for some advice on how to best resize/scale/crop in order to have the pdf look decent:

public SKBitmap CroppedBitmap(SKBitmap bitmap)
{
float desiredWidth = 1096;
float desiredHeight = 700;

        float left = ((bitmap.Width - desiredWidth) / 2) + 2;
        float top = ((bitmap.Height - desiredHeight) / 2) - 4;
        float right = left + desiredWidth;
        float bottom = top + desiredHeight;

        //SKRect cropRect = croppingRect.Rect;
        SKRect cropRect = new SKRect(left, top, right, bottom);
        SKBitmap croppedBitmap = new SKBitmap((int)cropRect.Width,
                                                (int)cropRect.Height);
        SKRect dest = new SKRect(0, 0, cropRect.Width, cropRect.Height);
        source = new SKRect(cropRect.Left, cropRect.Top,
                                    cropRect.Right, cropRect.Bottom);

        using (SKCanvas canvas = new SKCanvas(croppedBitmap))
        {
            canvas.DrawBitmap(bitmap, source, dest);
        }

        return croppedBitmap;         
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>