how to create shader for shapes.

Skip to first unread message

keep learning

Jul 27, 2022, 9:14:11 AM7/27/22
to skia-discuss
  I and drawn some shapes like circle , rectangle on canvas.
Now i was to create shader of the selected shape for eg rectangle . 

I tried few example on fiddle , like below :-

void draw(SkCanvas* canvas) {


    SkPaint paint;

    canvas->drawCircle(15, 10, 10, paint);

    SkImageInfo info = SkImageInfo::Make(30, 30, kBGRA_8888_SkColorType, kPremul_SkAlphaType);

    sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));

    //sk_bzero(data->writable_data(), info.minRowBytes() * info.height());

    canvas->readPixels(info, data->writable_data(), info.minRowBytes(), 0, 0);

    sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());

    canvas->drawImage(image, 10, 30);


Now , canvas can have multiple shapes . how i tell skia that i have to create shader for selected shape only ? 

seems form the code , canvas->readPixels will read all shapes on the canvas. 

I am new to skia and would appreciate  little help to going with my leaning.


Reply all
Reply to author
0 new messages