VB Code:
private int WarpBlit(Bitmap source, Bitmap dest, Point[] poly)
{
const int TL = 0, TR = 1, BR = 2, BL = 3;
Graphics gr = Graphics.FromImage(dest);
Vector top = new Vector(poly[TR].X - poly[TL].X, poly[TR].Y - poly[TL].Y, 0);
Vector bottom = new Vector(poly[BR].X - poly[BL].X, poly[BR].Y - poly[BL].Y, 0);
Vector left = new Vector(poly[BL].X - poly[TL].X, poly[BL].Y - poly[TL].Y, 0);
Vector right = new Vector(poly[BR].X - poly[TR].X, poly[BR].Y - poly[TR].Y, 0);
int numRows = (int)Math.Max(left.Magnitude(), right.Magnitude());
int numCols = (int)Math.Max(top.Magnitude(), bottom.Magnitude());
Vector slopeMultiplyer = (bottom - top) / numRows;
Vector start, finish, scan, temp;
Color pix;
for (int i = 0; i < numRows; i++)
{
start = new Vector(poly[TL].X, poly[TL].Y, 0) + (i * (left / numRows));
finish = new Vector(poly[TR].X, poly[TR].Y, 0) + (i * (right / numRows));
scan = (finish - start) / numCols;
for (int j = 0; j < numCols; j++)
{
temp = start + (j * scan);
pix = source.GetPixel((int)(source.Width * ((float)j / numCols)), (int)(source.Height * ((float)i / numRows)));
dest.SetPixel((int)temp.X, (int)temp.Y, pix);
}
}
return 0;
}