how to create shader for shapes.

18 views
Skip to first unread message

keep learning

unread,
Jul 27, 2022, 9:14:11 AMJul 27
to skia-discuss
Hello,
  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) {

    canvas->clear(SK_ColorBLUE);

    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.


Thanks,


Reply all
Reply to author
Forward
0 new messages