How to set stroke width for Canvas Context2d?

138 views
Skip to first unread message

mark

unread,
Aug 29, 2012, 6:44:21 PM8/29/12
to google-we...@googlegroups.com
Hi,

I'd like to change the stroke width but am not clear how to do this:

    Context2d context = ...;
    context.setStrokeStyle(FillStrokeStyle ?);
    context.strokeRect(…);

I'm not sure how to create a FillStrokeStyle object (or specifically how to create one where I can control its width). Anyone know?

Thanks



Chris Lercher

unread,
Aug 30, 2012, 2:24:27 AM8/30/12
to google-we...@googlegroups.com
To set the width of the stroke, use ctx.setLineWidth(double)

In general, FillStrokeStyle currently has three subclasses:

- CanvasGradient
- CanvasPattern
- CssColor

They don't have public constructors. CanvasGradient can be created by using ctx.createLinearGradient() or ctx.createRadialGradient().

CanvasPatterns can be created with ctx.createPattern().

CssColors can be created with CssColor.make(). There's also a shortcut: A CssColor object is created in the background, when you use some of the overloaded methods of Context2d like ctx.setStrokeStyle(String color) or ctx.setFillStyle(String color).

markww

unread,
Nov 12, 2012, 9:18:58 AM11/12/12
to google-we...@googlegroups.com
Thanks Chris, that's what I needed.
Reply all
Reply to author
Forward
0 new messages