简体   繁体   中英

Crop an Image, by specifing four corner points (non-rectangular)

Need to create a function, which crops an image, given four points.

Input:---------->Image, four corner points

Output:------->Cropped image

I have come across two types of cropping functions so far,

1)which uses a point, Height & width

2)which uses a point, height, width & an angle However these functions don't seem to solve my issue completely.

In order to be more clear, I have tried to depict my intentions in the image below. Cropping an image, by specifying corner points

Finally found the solution to my problem :)

// define quadrilateral's corners
List<IntPoint> corners = new List<IntPoint>( );
corners.Add( new IntPoint(  x1,  y1 ) );
corners.Add( new IntPoint( x2,  y2 ) );
corners.Add( new IntPoint( x3, y3 ) );
corners.Add( new IntPoint( x4, y4 ) );
// create filter
QuadrilateralTransformation filter=new QuadrilateralTransformationBilinear( corners, NewWidth, NewHeight );
// apply the filter
Bitmap newImage = filter.Apply( image );

This would convert any quadrilateral into a Rectangular one. It helped me, hope this information is helpful to others as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM