private static string ApplyMatrix(Rectangle RB, Rectangle GB, Rectangle R, Rectangle G, Rectangle B, Image g, double gx, double gy, double gw, double gh) { var p = new { R = new { x = Canvas.GetLeft(R), y = Canvas.GetTop(R) }, G = new { x = Canvas.GetLeft(G), y = Canvas.GetTop(G) }, B = new { x = Canvas.GetLeft(B), y = Canvas.GetTop(B) } }; var q = new { R = new { x = p.R.x - p.B.x, y = p.R.y - p.B.y }, G = new { x = p.G.x - p.B.x, y = p.G.y - p.B.y }, B = new { x = p.B.x - gx, y = p.B.y - gy }, }; RB.SetBounds(p.R.x, p.R.y, p.B.x, p.B.y); GB.SetBounds(p.G.x, p.G.y, p.B.x, p.B.y); var m = new { M11 = q.R.x / gw, M12 = q.R.y / gh, M21 = q.G.x / gw, M22 = q.G.y / gh, OX = q.B.x, OY = q.B.y }; var s = q.ToString() + Environment.NewLine + m.ToString(); g.RenderTransform = new MatrixTransform(m.M11, m.M12, m.M21, m.M22, m.OX, m.OY); return s; }