SkBitmap bitmap; // Load the bitmap SkIRect clipRect = SkIRect::MakeXYWH(10, 10, 100, 100); // Define the clipping region canvas->save(); // Save the current canvas state canvas->clipRect(clipRect); // Set the clipping region canvas->drawBitmap(bitmap, 0, 0); // Draw the bitmap (only the clipped region will be visible) canvas->restore(); // Restore the previous canvas state
SkPath path; // Define the path SkIRect clipRect = SkIRect::MakeXYWH(10, 10, 100, 100); // Define the clipping region canvas->save(); // Save the current canvas state canvas->clipRect(clipRect); // Set the clipping region canvas->drawPath(path, paint); // Draw the path (only the clipped region will be visible) canvas->restore(); // Restore the previous canvas stateIn this example, the clipRect() method is used to clip the path to a rectangular region defined by the `clipRect` variable. Overall, the SkCanvas clipRect() method is a useful tool for controlling the drawing region of a canvas for more complex graphics rendering.