#include "SkCanvas.h" #include "SkColor.h" // Create a 640x480 canvas with a white background SkBitmap bitmap; bitmap.allocN32Pixels(640, 480); SkCanvas canvas(bitmap); canvas.drawColor(SK_ColorWHITE); // Clear the canvas to black canvas.clear(SK_ColorBLACK);
#include "SkCanvas.h" #include "SkColor.h" // Create a 640x480 canvas with a white background SkBitmap bitmap; bitmap.allocN32Pixels(640, 480); SkCanvas canvas(bitmap); canvas.drawColor(SK_ColorWHITE); // Clear the canvas with transparency SkColor transparent = SkColorSetARGB(0, 0, 0, 0); canvas.clear(transparent);
#include "SkCanvas.h" #include "SkColor.h" #include "SkGradientShader.h" // Create a 640x480 canvas with a white background SkBitmap bitmap; bitmap.allocN32Pixels(640, 480); SkCanvas canvas(bitmap); canvas.drawColor(SK_ColorWHITE); // Create a gradient shader SkPoint startPoint = SkPoint::Make(0, 0); SkPoint endPoint = SkPoint::Make(0, 480); SkColor colors[2] = { SK_ColorBLUE, SK_ColorGREEN }; SkGradientShader::GradientStop stops[2] = { { 0, 0 }, { 1, 1 } }; sk_spIn this example, we first create a canvas with a white background. We then use the SkGradientShader class to create a linear gradient from blue to green. Finally, we use the drawPaint() function to fill the canvas with the gradient. Package library: Skia Graphics Librarygradient = SkGradientShader::MakeLinear( startPoint, endPoint, colors, stops, 2, SkTileMode::kClamp); // Clear the canvas with the gradient shader canvas.drawPaint(SkPaint(gradient));