Skiasharp: [QUESTION] How to get bitmap cropped by any quadrangle

Created on 15 Apr 2020  路  3Comments  路  Source: mono/SkiaSharp

Hello.

Is it possible to cut a bitmap fragment from the quadrangle, which is marked with four points?
I create app which take a photo and then allow user to crop that image. But user can create a non rectangle shapes. I know i need to do a matrix transformation to return normal image but i don't know how to get specific part of bitmap to transform

Can u help me?
Thanks in advance for the answer.

type-question

Most helpful comment

Do you also want to apply a perspective transformation to the cropped polygon, so that the polygon is transformed into a square?

If so, it seems SkiaSharp 1.68 is currently missing some Skia/C++ methods to create a perspective matrix that maps a quadrilateral to another quadrilateral, e.g. the setPolyToPoly method

If need that, you could convert this C++ code to C# for now

All 3 comments

This is pretty easy to do, once you have the image and the path that you wish to crop, create a new surface, clip and draw.

I have an example app here:
https://github.com/mattleibow/SkiaSharpImageCropper/blob/master/ImageCropper/ImageCropper/MainPage.xaml.cs#L104

Do you also want to apply a perspective transformation to the cropped polygon, so that the polygon is transformed into a square?

If so, it seems SkiaSharp 1.68 is currently missing some Skia/C++ methods to create a perspective matrix that maps a quadrilateral to another quadrilateral, e.g. the setPolyToPoly method

If need that, you could convert this C++ code to C# for now

Thank you for replies.
This is exactly what i was looking for. Works great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joreg picture joreg  路  4Comments

parthipanr picture parthipanr  路  4Comments

NotOfficer picture NotOfficer  路  3Comments

michaldobrodenka picture michaldobrodenka  路  3Comments

alanricker picture alanricker  路  3Comments