Is there any way to draw an image to use 4 points rather than 3 (perspective warp)

半世苍凉 提交于 2019-12-20 02:59:10

问题


Drawing a parallelgram is nicely supported with Graphics.DrawImage:

Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
using (Graphics gr = new Graphics.FromImage(destImage))
{
    Point[] destPts = new Point[] { new PointF(x1, y1), 
        new PointF(x2, y2), new PointF(x4, y4)};
    gr.DrawImage(srcImage, destPts);

How, do you do 4 points (obviously the following is not supported, but this is what is wanted):

Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
using (Graphics gr = new Graphics.FromImage(destImage))
{
    Point[] destPts = new Point[] { new PointF(x1, y1), new PointF(x2, y2),
        new PointF(x3, y3), new PointF(x4, y4)};
    gr.DrawImage(srcImage, destPts);
}

回答1:


Closest I can find is this information, which is extremely laggy.




回答2:


Normally you would do this with a 3x3 Matrix, but the Matrix class only lets you specify 6 values instead of 9. You might be able to do this in Direct X.




回答3:


When thinking of how 3D tools would handle it... try drawing a triangle of one half and then the other triangle for the other half. So if you have points A, B, C, & D; you would draw (with a clipping plane) A, B, C and then B, C, D, or something of the sort.




回答4:


I found the following article in CodeProject: Free Image Transformation By YLS

needs some works

maybe you can use this :)



来源:https://stackoverflow.com/questions/38308/is-there-any-way-to-draw-an-image-to-use-4-points-rather-than-3-perspective-war

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!