久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

HTML5 Canvas如何實現(xiàn)紋理填充與描邊(Fill And Stroke

HTML5 Canvas如何實現(xiàn)紋理填充與描邊(Fill And Stroke)_html5教程技巧HTML5中文學(xué)習(xí)網(wǎng),是中國最大的HTML5中文門戶,為廣大HTML5愛好者提供各種HTML5資料,包括HTML5網(wǎng)站、HTML5資訊、HTML5應(yīng)用、HTM
點評:本文為大家詳細(xì)介紹下HTML5 Canvas Fill 與Stroke文字效果,基于Canvas如何實現(xiàn)紋理填充與描邊、顏色填充與描邊,具體代碼如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
 
 

演示HTML5 Canvas Fill 與Stroke文字效果,基于Canvas如何實現(xiàn)紋理填充與描邊。

一:顏色填充與描邊
顏色填充可以通過fillStyle來實現(xiàn),描邊顏色可以通過strokeStyle來實現(xiàn)。簡單示例
如下:

 

復(fù)制代碼
代碼如下:

// fill and stroke text
ctx.font = '60pt Calibri';
ctx.lineWidth = 3;
ctx.strokeStyle = 'green';
ctx.strokeText('Hello World!', 20, 100);
ctx.fillStyle = 'red';
ctx.fillText('Hello World!', 20, 100);
 


二:紋理填充與描邊
HTML5 Canvas還支持紋理填充,通過加載一張紋理圖像,然后創(chuàng)建畫筆模式,創(chuàng)建紋理模式的API為ctx.createPattern(imageTexture,"repeat");第二參數(shù)支持四個值,分別為”repeat-x”, ”repeat-y”, ”repeat”,”no-repeat”意思是紋理分別沿著X軸,Y軸,XY方向沿重復(fù)或者不重復(fù)。紋理描邊與填充的代碼如下:

 

復(fù)制代碼
代碼如下:

var woodfill = ctx.createPattern(imageTexture,"repeat");
ctx.strokeStyle = woodfill;
ctx.strokeText('Hello World!', 20, 200);
// fill rectangle
ctx.fillStyle = woodfill;
ctx.fillRect(60, 240, 260, 440);
 


紋理圖片:
 
三:運行效果
 
代碼:

 

復(fù)制代碼
代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=IE8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Canvas Fill And Stroke Text Demo</title>
<link href="default.css" rel="stylesheet" />
<script>
var ctx = null; // global variable 2d context
var imageTexture = null;
window.onload = function() {
var canvas = document.getElementById("text_canvas");
console.log(canvas.parentNode.clientWidth);
canvas.width = canvas.parentNode.clientWidth;
canvas.height = canvas.parentNode.clientHeight;
if (!canvas.getContext) {
console.log("Canvas not supported. Please install a HTML5 compatible browser.");
return;
}
// get 2D context of canvas and draw rectangel
ctx = canvas.getContext("2d");
ctx.fillStyle="black";
ctx.fillRect(0, 0, canvas.width, canvas.height);
// fill and stroke text
ctx.font = '60pt Calibri';
ctx.lineWidth = 3;
ctx.strokeStyle = 'green';
ctx.strokeText('Hello World!', 20, 100);
ctx.fillStyle = 'red';
ctx.fillText('Hello World!', 20, 100);
// fill and stroke by pattern
imageTexture = document.createElement('img');
imageTexture.src = "../pattern.png";
imageTexture.onload = loaded();
}
function loaded() {
// delay to image loaded
setTimeout(textureFill, 1000/30);
}
function textureFill() {
// var woodfill = ctx.createPattern(imageTexture, "repeat-x");
// var woodfill = ctx.createPattern(imageTexture, "repeat-y");
// var woodfill = ctx.createPattern(imageTexture, "no-repeat");
var woodfill = ctx.createPattern(imageTexture, "repeat");
ctx.strokeStyle = woodfill;
ctx.strokeText('Hello World!', 20, 200);
// fill rectangle
ctx.fillStyle = woodfill;
ctx.fillRect(60, 240, 260, 440);
}
</script>
</head>
<body>
<h1>HTML5 Canvas Text Demo - By Gloomy Fish</h1>
<pre>Fill And Stroke</pre>
<div id="my_painter">
<canvas id="text_canvas"></canvas>
</div>
</body>
</html>
 


 

 
 
【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

這篇文章主要介紹了有關(guān)HTML5頁面在iPhoneX適配問題,需要的朋友可以參考下
本篇文章主要介紹了html5中canvas圖表實現(xiàn)柱狀圖的示例,本文使用canvas來實現(xiàn)一個圖表,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
Adobe公司出品的多媒體處理軟件產(chǎn)品線較多,涵蓋了音視頻編輯、圖像處理、平面設(shè)計、影視后期等領(lǐng)域。這篇文章主要介紹了Adobe Html5 Extension開發(fā)初體驗圖文教程,非常不錯,需要的朋
這篇文章主要介紹了基于HTML5的WebGL經(jīng)典3D虛擬機(jī)房漫游動畫,需要的朋友可以參考下
這篇文章主要介紹了html5實現(xiàn)移動端適配完美寫法,需要的朋友可以參考下
本篇文章主要介紹了HTML5響應(yīng)式(自適應(yīng))網(wǎng)頁設(shè)計的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
主站蜘蛛池模板: 亚洲欧美日韩一区二区 | 日日天天| 久久久久久久综合色一本 | 亚洲色欲色欲www | 久久99蜜桃综合影院免费观看 | www.天天干.com | 日韩精品一区二区三区视频播放 | 久久国产欧美日韩精品 | 91原创视频在线观看 | 在线日韩欧美 | 亚洲啊v在线 | 亚洲人在线播放 | 国产一区二区精品 | 国产乱码精品1区2区3区 | 自拍偷拍一区二区三区 | 春色av| 精品一二三区在线观看 | 三级高清| 国产毛片毛片 | 欧美国产日韩在线观看成人 | 国产欧美精品区一区二区三区 | 一级毛片免费完整视频 | 亚洲视频中文字幕 | 欧美人妖网站 | 欧美一级黄色片免费观看 | 精品日韩欧美一区二区 | av中文字幕在线观看 | 日韩成人免费视频 | 啪啪精品| av天天看| 最新av中文字幕 | 伊人伊人网 | 日韩精品一区二区三区 | 国产免费福利小视频 | 午夜影院网站 | 91小视频在线 | 国产www成人 | 男人av的天堂 | wwww.8888久久爱站网 | 黄色三级在线播放 | 欧美一区二区免费电影 |