How to draw array of pixels?

Skip to first unread message

abhishek kumar

Apr 7, 2022, 11:10:09 AMApr 7
to skia-discuss
i want to know how to draw array of pixels.
my program is like

void OnDraw(SkCanvas* canvas)

    int *pixels=new int[w*h]; //this array of pixels and i want to draw

    delete[] pixels

George Wright

Apr 18, 2022, 8:08:55 PMApr 18
You can either wrap that pixel pointer in an SkPixmap object, then you can create an SkImage from the SkPixmap using SkImage::MakeFromRaster(SkPixmap) and use SkCanvas::drawImage() to draw the resulting SkImage to the canvas. This codepath is similar to drawing any other raster image, and will respect clips, transforms, paint attributes etc.

Alternatively, you can call SkCanvas::writePixels() to write the raw pixel data directly into the SkCanvas. This ignores the currently set transform and clip.

Without knowing your usecase it's hard to recommend one or the other.


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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages