Canvas fillText() Method

Definition and Usage

fillText() Method to draw filled text on the canvas. The default text color is black.

Hint:Please use font Property to define font and size, and use fillStyle Properties to render text in another color/gradient.

ਉਦਾਹਰਣ

use fillText() to write text "Hello world!" and "codew3c.com" on the canvas:

ਤੁਹਾਡਾ ਬਰਾਉਜ਼ਰ HTML5 ਕੈਂਵਾਸ ਟੈਗ ਨੂੰ ਸਮਰਥਨ ਨਹੀਂ ਦਿੰਦਾ ਹੈ。

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="20px Georgia";
ctx.fillText("Hello World!",10,50);
ctx.font="30px Verdana";
// ਗ੍ਰੇਡੀਐਂਟ ਬਣਾਓ
var gradient=ctx.createLinearGradient(0,0,c.width,0);
gradient.addColorStop("0","magenta");
gradient.addColorStop("0.5","blue");
gradient.addColorStop("1.0","red");
// ਗ੍ਰੇਡੀਐਂਟ ਨਾਲ ਰੰਗ ਭਰੋ
ctx.fillStyle=gradient;
ctx.fillText("codew3c.com",10,90);

ਆਪਣੇ ਅਨੁਭਵ ਲਈ ਪ੍ਰਯੋਗ ਕਰੋ

ਸ਼ਬਦਬੱਧ

context.fillText(text,x,y,maxWidth);

ਪੈਰਾਮੀਟਰ ਦਾ ਮੁੱਲ

ਪੈਰਾਮੀਟਰ ਵਰਣਨ
text ਪੇਂਟਬੋਰਡ 'ਤੇ ਬਾਹਰ ਕੀਤੇ ਗਏ ਟੈਕਸਟ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ。
x ਟੈਕਸਟ ਦੇ ਚਿੱਤਰਣ ਦੀ ਸ਼ੁਰੂਆਤ ਦੀ x ਅਕਸਰਣ ਸਥਾਨ (ਪੇਂਟਬੋਰਡ ਨਾਲ ਸਬੰਧਤ ਹੈ)।
y ਟੈਕਸਟ ਦੇ ਚਿੱਤਰਣ ਦੀ ਸ਼ੁਰੂਆਤ ਦੀ y ਅਕਸਰਣ ਸਥਾਨ (ਪੇਂਟਬੋਰਡ ਨਾਲ ਸਬੰਧਤ ਹੈ)।
maxWidth ਚੋਣੀ ਯੋਗ ਹੈ। ਮਹਿੰਮਤ ਸਭ ਤੋਂ ਵੱਡਾ ਟੈਕਸਟ ਚੌਡਾਈ ਪਿਕਸਲ ਵਿੱਚ ਹੈ।

ਬਰਾਉਜ਼ਰ ਸਮਰਥਨ

ਇਸ ਤੇਲ ਵਿੱਚ ਸੰਖਿਆਵਾਂ ਪਹਿਲੀ ਵਾਰ ਇਸ ਵਿਸ਼ੇਸ਼ਤਾ ਨੂੰ ਸਮਰਥਨ ਕਰਨ ਵਾਲੇ ਬਰਾਉਜ਼ਰ ਦੀ ਵਰਜਨ ਨੂੰ ਦਰਸਾਉਂਦੀਆਂ ਹਨ。

ਚਾਰੋਕੇ ਐਜ਼ਡ ਫਾਇਰਫਾਕਸ ਸਫਾਰੀ ਓਪਰਾ
ਚਾਰੋਕੇ ਐਜ਼ਡ ਫਾਇਰਫਾਕਸ ਸਫਾਰੀ ਓਪਰਾ
4.0 9.0 3.6 4.0 10.1

ਟਿੱਪਣੀਆਂ:Internet Explorer 8 ਅਤੇ ਘੱਟ ਤੋਂ ਘੱਟ ਵਰਜਨ ਨਹੀਂ <canvas> ਇਲੈਕਟ੍ਰੌਨ