#include "SkCanvas.h" #include "SkImage.h" void drawImage(SkCanvas* canvas, SkImage* image) { SkRect rect = SkRect::MakeWH(image->width(), image->height()); canvas->drawImage(image, 0, 0, &rect, nullptr); } int main() { SkBitmap bitmap; SkImage* image = SkImage::MakeFromBitmap(bitmap); drawImage(canvas, image); ... }
#include "SkCanvas.h" #include "SkImage.h" void drawImage(SkCanvas* canvas, SkImage* image, float scaleX, float scaleY) { SkRect rect = SkRect::MakeWH(image->width() * scaleX, image->height() * scaleY); canvas->drawImageRect(image, nullptr, rect, nullptr); } int main() { SkBitmap bitmap; SkImage* image = SkImage::MakeFromBitmap(bitmap); drawImage(canvas, image, 2.0f, 2.0f); ... }This code shows how to draw a scaled image on a canvas using SkCanvas drawBitmap. The function drawImage takes a canvas, an image, and scaleX and scaleY as arguments. It creates an SkRect that is scaled by the scaleX and scaleY factors and then calls SkCanvas's drawImageRect function with the scaled rect. This code uses the Skia Graphics Library.