Perspective Image Distortion

前端 未结 5 1190
旧时难觅i
旧时难觅i 2021-01-14 02:17

The application I am working on currently requires functionality for Perspective Image Distortion. Basically what I want to do is to allow users to load an image into the ap

5条回答
  •  伪装坚强ぢ
    2021-01-14 03:06

    This seems to be exactly what you (and I) were looking for: http://www.codeproject.com/KB/graphics/YLScsFreeTransform.aspx

    It will take an image and distort it using 4 X/Y coordinates you provide.

    Fast, free, simple code. Tested and it works beautifully. Simply download the code from the link, then use FreeTransform.cs like this:

    using (System.Drawing.Bitmap sourceImg = new System.Drawing.Bitmap(@"c:\image.jpg")) 
    { 
        YLScsDrawing.Imaging.Filters.FreeTransform filter = new YLScsDrawing.Imaging.Filters.FreeTransform(); 
        filter.Bitmap = sourceImg;
        // assign FourCorners (the four X/Y coords) of the new perspective shape
        filter.FourCorners = new System.Drawing.PointF[] { new System.Drawing.PointF(0, 0), new System.Drawing.PointF(300, 50), new System.Drawing.PointF(300, 411), new System.Drawing.PointF(0, 461)}; 
        filter.IsBilinearInterpolation = true; // optional for higher quality
        using (System.Drawing.Bitmap perspectiveImg = filter.Bitmap) 
        {
            // perspectiveImg contains your completed image. save the image or do whatever.
        } 
    } 
    

提交回复
热议问题