Rotating image on canvas

110 views
Skip to first unread message

Kyra Moed

unread,
Mar 23, 2021, 1:50:44 PM3/23/21
to skia-d...@googlegroups.com
Hi all,

I'm trying to rotate an image that's drawn on a canvas, and the rotate() function doesn't seem to be working. 
Here's an example of what I'm trying to do (assuming doc and img are already defined):

sk_sp<SkDocument> doc;
sk_sp<SkImage> img;
SkCanvas* canvas = doc->beginPage(img->width(), img->height());
canvas->drawImage(img, 0, 0); 
canvas->rotate(90);  //rotate the image on the canvas 90 degrees
doc->endPage();


Any ideas on why this isn't working?

Greg Daniel

unread,
Mar 23, 2021, 1:54:04 PM3/23/21
to skia-discuss
The canvas has state in regards to the current matrix. When you do a draw call it grabs that current state and uses it for the draw. In this case you are calling the draw before you've set the matrix on the canvas. So it draws as if there was an identity matrix. You are not doing any more draws after you change the matrix on the canvas, so there are no draws that will respect that matrix.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAJLbM8PCpDYsC17FNJy7EsLUxy0ND75v7rfWHzVDT%3Dk7L8W8wg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages