public ImageData Clone() { ImageData cb = new ImageData(); cb.A = (byte[,])_alpha.Clone(); cb.B = (byte[,])_blue.Clone(); cb.G = (byte[,])_green.Clone(); cb.R = (byte[,])_red.Clone(); return cb; }
private Bitmap getTransformedBitmap() { if (srcH == 0 || srcW == 0) return null; ImageData destCB = new ImageData(); destCB.A = new byte[rect.Width, rect.Height]; destCB.B = new byte[rect.Width, rect.Height]; destCB.G = new byte[rect.Width, rect.Height]; destCB.R = new byte[rect.Width, rect.Height]; PointF ptInPlane = new PointF(); int x1, x2, y1, y2; double dab, dbc, dcd, dda; float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2, nbyte; for (int y = 0; y < rect.Height; y++) { for (int x = 0; x < rect.Width; x++) { Point srcPt = new Point(x, y); srcPt.Offset(this.rect.Location); if (isOnPlaneABCD(srcPt)) { dab = Math.Abs(Vector.CrossProduct(new Vector(srcPt.X - vertex[0].X, srcPt.Y - vertex[0].Y), AB)); dbc = Math.Abs(Vector.CrossProduct(new Vector(srcPt.X - vertex[1].X, srcPt.Y - vertex[1].Y), BC)); dcd = Math.Abs(Vector.CrossProduct(new Vector(srcPt.X - vertex[2].X, srcPt.Y - vertex[2].Y), CD)); dda = Math.Abs(Vector.CrossProduct(new Vector(srcPt.X - vertex[3].X, srcPt.Y - vertex[3].Y), DA)); ptInPlane.X = (float)(srcW * (dda / (dda + dbc))); ptInPlane.Y = (float)(srcH * (dab / (dab + dcd))); x1 = (int)ptInPlane.X; y1 = (int)ptInPlane.Y; if (x1 >= 0 && x1 < srcW && y1 >= 0 && y1 < srcH) { if (isBilinear) { x2 = (x1 == srcW - 1) ? x1 : x1 + 1; y2 = (y1 == srcH - 1) ? y1 : y1 + 1; dx1 = ptInPlane.X - (float)x1; if (dx1 < 0) dx1 = 0; dx1 = 1f - dx1; dx2 = 1f - dx1; dy1 = ptInPlane.Y - (float)y1; if (dy1 < 0) dy1 = 0; dy1 = 1f - dy1; dy2 = 1f - dy1; dx1y1 = dx1 * dy1; dx1y2 = dx1 * dy2; dx2y1 = dx2 * dy1; dx2y2 = dx2 * dy2; nbyte = srcCB.A[x1, y1] * dx1y1 + srcCB.A[x2, y1] * dx2y1 + srcCB.A[x1, y2] * dx1y2 + srcCB.A[x2, y2] * dx2y2; destCB.A[x, y] = (byte)nbyte; nbyte = srcCB.B[x1, y1] * dx1y1 + srcCB.B[x2, y1] * dx2y1 + srcCB.B[x1, y2] * dx1y2 + srcCB.B[x2, y2] * dx2y2; destCB.B[x, y] = (byte)nbyte; nbyte = srcCB.G[x1, y1] * dx1y1 + srcCB.G[x2, y1] * dx2y1 + srcCB.G[x1, y2] * dx1y2 + srcCB.G[x2, y2] * dx2y2; destCB.G[x, y] = (byte)nbyte; nbyte = srcCB.R[x1, y1] * dx1y1 + srcCB.R[x2, y1] * dx2y1 + srcCB.R[x1, y2] * dx1y2 + srcCB.R[x2, y2] * dx2y2; destCB.R[x, y] = (byte)nbyte; } else { destCB.A[x, y] = srcCB.A[x1, y1]; destCB.B[x, y] = srcCB.B[x1, y1]; destCB.G[x, y] = srcCB.G[x1, y1]; destCB.R[x, y] = srcCB.R[x1, y1]; } } } } } return destCB.ToBitmap(); }