// Create a matrix SkMatrix matrix; // Define a source rectangle SkRect srcRect = SkRect::MakeXYWH(0, 0, 100, 100); // Define a destination rectangle SkRect destRect = SkRect::MakeXYWH(0, 0, 200, 200); // Set the matrix to scale the source rectangle to the destination rectangle matrix.setRectToRect(srcRect, destRect, SkMatrix::kFill_ScaleToFit); // Apply the matrix to a point (50, 50) SkPoint point = { 50, 50 }; matrix.mapPoints(&point, 1); // The resulting point is (100, 100)
// Create a matrix SkMatrix matrix; // Define a source rectangle SkRect srcRect = SkRect::MakeXYWH(0, 0, 100, 100); // Define a destination rectangle SkRect destRect = SkRect::MakeXYWH(0, 0, 200, 100); // Set the matrix to skew the source rectangle to the destination rectangle matrix.setRectToRect(srcRect, destRect, SkMatrix::kFill_ScaleToFit); // Apply the matrix to a point (50, 50) SkPoint point = { 50, 50 }; matrix.mapPoints(&point, 1); // The resulting point is (133.33, 50)This example demonstrates how to use setRectToRect to create a matrix that skews a rectangle from the source rectangle size of (100, 100) to the destination rectangle size of (200, 100) at a 60-degree angle. The kFill_ScaleToFit parameter sets the matrix order to fill the destination rectangle while preserving the aspect ratio. The resulting matrix is used to transform a point to (133.33, 50). Overall, setRectToRect is a useful method for creating matrices that transform graphics objects from one rectangle to another with a specified matrix order. Its ability to handle various parameter combinations makes it a versatile tool for graphics programming. The package library is Skia, which is commonly used in Android and Chrome development.