Add Drop Shadow on Texts

1,424 views
Skip to first unread message

Jay Van Diyk

unread,
Jul 28, 2013, 1:33:02 AM7/28/13
to skia-d...@googlegroups.com
Hi,

How do I add shadow on texts?? I can successfully draw the text, but I would like to have a little drop shadow effect on it.

Any thoughts?

thanks.

bungeman

unread,
Jul 28, 2013, 1:41:12 PM7/28/13
to skia-d...@googlegroups.com
Look in Skia's gm/blurs.cpp for an example (there's a comment '//drawText' with the relevant code). At a low level, you want to install a SkBlurMaskFilter on the paint to draw blurred text, then draw the non-blurred text on top. Alternatively, you could install a SkBlurDrawLooper on the paint, see gm/shadows.cpp for an example. The SkBlurDrawLooper takes care of the the low level details for you.

Mike Reed

unread,
Jul 29, 2013, 9:16:50 AM7/29/13
to skia-d...@googlegroups.com
... SkLayerDrawLoopers is more general, and gets a *lot* more attention (it is used by chrome/android). Consider SkBlurDrawLooper DEPRECATED...


--
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 post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jay Van Diyk

unread,
Jul 29, 2013, 12:52:52 PM7/29/13
to skia-d...@googlegroups.com
Thank you. Will give it a try! :)
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/iPuPYVUjcLE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.

tuệ việt trí

unread,
Apr 24, 2016, 6:15:56 AM4/24/16
to skia-discuss
Hi, I encountered a problem as you! you can help me! thank you!

Vào 12:33:02 UTC+7 Chủ Nhật, ngày 28 tháng 7 năm 2013, Jay Van Diyk đã viết:

Jim Van Verth

unread,
Apr 25, 2016, 8:49:05 AM4/25/16
to skia-discuss
You can do this with an SkLayerDrawLooper. If you look at gm/drawlooper.cpp, you'll see an example of how to set one up. Essentially you use a builder to build up paint information for each layer, then assign the resulting looper to the SkPaint. When you draw the text, it will render it with each layer's information in turn. So one layer would be the regular text, and the other would be the shadow.

--
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 post to this group, send email to skia-d...@googlegroups.com.

Mike Reed

unread,
Apr 25, 2016, 10:06:14 AM4/25/16
to skia-d...@googlegroups.com
True enough, but know that there is nothing special about layerdrawlooper, and in the very long run we may remove it. All that it does is to make several draw calls in a row, which you can do directly, where each draw modifies the paint and/or the canvas.

Hal Canary

unread,
Apr 25, 2016, 10:44:27 AM4/25/16
to skia-discuss
    const char text[] = "Skia";
    const SkScalar radius = 1.0f;
    const SkScalar xDrop = 2.0f;
    const SkScalar yDrop = 2.0f;
    const SkScalar x = 4.0f;
    const SkScalar y = 26.0f;
    const SkScalar textSize = 24.0f;
    const uint8_t blurAlpha = 127;
    canvas->drawColor(SK_ColorWHITE);
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setTextSize(textSize);
    SkPaint blur(paint);
    blur.setAlpha(blurAlpha);
    blur.setMaskFilter(SkBlurMaskFilter::Make(
        kNormal_SkBlurStyle, 
        SkBlurMaskFilter::ConvertRadiusToSigma(radius), 0));
    canvas->drawText(text, strlen(text), x + xDrop, y + yDrop, blur);
    canvas->drawText(text, strlen(text), x, y, paint);

Mike Reed

unread,
Apr 25, 2016, 11:05:11 AM4/25/16
to skia-d...@googlegroups.com
Do we have named-fiddles yet for our FAQ?

Hal Canary

unread,
Apr 25, 2016, 12:29:56 PM4/25/16
to skia-discuss
Reply all
Reply to author
Forward
0 new messages