D
D
dom1n1k2012-05-15 13:03:09
JavaScript
dom1n1k, 2012-05-15 13:03:09

Canvas: Is it possible to get the ColorStop value from a gradient?

I am already almost sure that the answer to my question is “no”, because. I googled a lot - but I'll ask just in case ...

// формируем градиент
var lingrad = ctx.createLinearGradient(0, 0, 0, 200);  
lingrad.addColorStop(0, '#FFFFFF');  
lingrad.addColorStop(0.5, '#8080FF');
lingrad.addColorStop(1, '#000000');

// а получить из готового? что-то наподобии такого:
var color = lingrad.getColorStop(0).color;  // #FFFFFF
var position = lingrad.getColorStop(0).position;  // 0

I'm very surprised that the Canvas API doesn't have such a feature.
Okay, there is no way to get the color back from ctx.fillStyle yet, but if it is still in an intermediate variable - why not allow reading?
Not to mention changing the selective color.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ag666, 2012-05-15
@ag666

As far as I know, the Canvas API is pretty “low-level” - if you want convenience, you need to “wrap” the methods yourself. Write a library, so to speak.

P
Pavlo Ponomarenko, 2012-05-15
@TheShock

Excuse me, what's the purpose?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question