How to draw array of pixels?

29 views
Skip to first unread message

abhishek kumar

unread,
Apr 7, 2022, 11:10:09 AMApr 7
to skia-discuss
hi 
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

unread,
Apr 18, 2022, 8:08:55 PMApr 18
to skia-d...@googlegroups.com
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.

George

--
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/7322a497-573a-4e22-b65f-50e227e68a38n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages