728x90
<canvas id="myCanvas" height="400" width="400" style="border:red 1px solid"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('myCanvas').getContext("2d");
// 단색으로 채우기 ; 투명도 1.0
ctx.lineWidth = "15";
ctx.strokeStyle = "blue";
ctx.strokeRect(30,30,150,150);
ctx.fillStyle = 'red'; // 채우기 색 지정
ctx.globalAlpha = "1.0"; // 채우기 투명도 설정
ctx.fillRect(30,30,150,150);
//단색으로 채우기 ; 투명도 0.1
ctx.fillStyle = "red";
ctx.globalAlpha = "0.1";
ctx.fillRect(200,30,150,150);
//단색으로 채우기 ; 투명도 0.4
ctx.fillStyle = "red";
ctx.globalAlpha = "0.4";
ctx.fillRect(30,200,150,150);
//단색으로 채우기 ; 투명도 0.7
ctx.fillStyle = "red";
ctx.globalAlpha = "0.7";
ctx.fillRect(200,200,150,150);
</script>
HTML5 canvas - 채우기 스타일 지정하기 (fillStyle, globalAlpha)
* fill() 메소드 사용하는 경우에 fillStyle, globalAlpha 사용
※ stroke() <=> strokeStyle 속성
* 속성
- fillStyle => 채우기 색 지정
- globalAlpha => 색의 투명도 값 (0.0 ~1.0 ) 지정
결과보기 >
출처 : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=javaking75&logNo=140170247450
HTML5 canvas - 채우기 스타일(색상) 지정하기 (fillStyle;채우기, globalAlpha;투명도 )
HTML5 canvas - 채우기 스타일 지정하기 (fillStyle, globalAlpha) * fill() 메소드 사용하는 경우에...
blog.naver.com
728x90
'Front end > JS (JavaScript)' 카테고리의 다른 글
자바스크립트(JavaScript) html select 선택시 이벤트, select 태그 option submit (0) | 2022.08.26 |
---|---|
자바스크립트(JavaScript) - floodfill, 플러드필, 이미지에 색칠하기, 그림판, 이미지 클릭시 색채우기 (0) | 2022.08.25 |
자바, 자바스크립트 브라우저별 User-Agent로직, User-Agent 를 이용한 브라우저 체크 [펌] (0) | 2022.08.12 |
자바스크립트(JavaScript) 클래스 추가, 제거 , 토글 (addClass, removeClass, toggleClass) (0) | 2022.08.10 |
자바스크립트(JavaScript) 경고창 alert에서 텍스트 줄바꿈 (0) | 2022.07.15 |