Is it more efficient to set opacity on a rectangle or its fill?
开发者_如何学JAVAI have a LinearGradiant defined that I use as the fill color for a rectangle. Now say I want the opacity of it to be (.30)
I was wondering if its more performant to set the opacity property directly on the rectangle or to set the stop-opacity property on each stop of the LinearGradiant?
I think that depends on whether you want the gradient to be transparent (and every use of it) or the actual rectangle (including maybe its stroke).
I wouldn't worry about performance or efficiency in this case, but more about what you're actually modelling (i.e. a transparent rectangle filled with a gradient or a rectangle filled with a transparent gradient).
If you only use the gradient once and the rectangle has no stroke then I'd probably go with just setting the opacity property on the rectangle because it's simpler (and for very colorful gradients setting every stop with an opacity becomes cumbersome). Likewise, if the rectangle has a stroke, then use fill-opacity
instead.
But as noted, that becomes moot if you re-use the gradient and then have to ask yourself »what does this gradient represent?«.
精彩评论