JS Reference

JS by Category JS by Alphabet

JavaScript

JS Array JS Boolean JS Classes JS Date JS Error JS Global JS JSON JS Math JS Number JS Operators JS RegExp JS Statements JS String

Window

Window Object Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

DOM Document DOM Element DOM Attributes DOM Events DOM Event Objects DOM HTMLCollection DOM Style
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundRepeat backgroundClip backgroundOrigin backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap cssFloat font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

Web APIs

API Console API Fullscreen API Geolocation API History API MediaQueryList API Storage

HTML Objects

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

Other References

CSSStyleDeclaration JS Conversion


HTML 캔버스 createImageData() 메서드

❮ 캔버스 개체

예시

모든 픽셀이 빨간색인 100*100픽셀 ImageData 개체를 만들고 캔버스에 넣습니다.

브라우저는 HTML5캔버스태그를 지원하지 않습니다.

자바스크립트:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var imgData = ctx.createImageData(100, 100);
for (var i = 0; i < imgData.data.length; i += 4)
  {
  imgData.data[i+0] = 255;
  imgData.data[i+1] = 0;
  imgData.data[i+2] = 0;
  imgData.data[i+3] = 255;
  }
ctx.putImageData(imgData, 10, 10);

브라우저 지원

표의 숫자는 이 방법을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.

Method
createImageData() 4.0 9.0 3.6 4.0 10.1

정의 및 사용

createImageData() 메서드는 비어 있는 새 ImageData 객체를 만듭니다. 새 개체의 픽셀 값은 기본적으로 투명한 검정색입니다.

ImageData 객체의 모든 픽셀에는 RGBA 값인 네 가지 정보가 있습니다.

R - 빨간색(0-255에서)
G - 녹색(0-255에서)
B - 파란색(0-255에서)
A - 알파 채널(0-255에서, 0은 투명하고 255는 투명) 완전히 볼 수 있음)

따라서 투명한 검정색은 (0, 0, 0, 0)을 나타냅니다.

색상/알파 정보는 배열에 보관되며 배열에는 모든 픽셀에 대해 4개의 정보가 포함되어 있으므로 배열의 크기는 ImageData 개체 크기의 4배인 너비*높이*4입니다. (배열의 크기를 찾는 더 쉬운 방법은 ImageDataObject.data.length를 사용하는 것입니다)

색상/알파 정보를 포함하는 배열 은 ImageData 객체 의 data 속성에 저장됩니다.

팁: 배열의 색상/알파 정보를 조작한 후에는 putImageData() 메서드 를 사용하여 이미지 데이터를 다시 캔버스에 복사할 수 있습니다 .

예:

ImageData 객체의 첫 번째 픽셀을 빨간색으로 만드는 구문:

imgData = ctx.createImageData(100, 100);

imgData.data[0] = 255;
imgData.data[1] = 0;
imgData.data[2] = 0;
imgData.data[3] = 255;

ImageData 객체의 두 번째 픽셀을 녹색으로 만드는 구문:

imgData = ctx.createImageData(100, 100);

imgData.data[4] = 0;
imgData.data[5] = 255;
imgData.data[6] = 0;
imgData.data[7] = 255;


자바스크립트 구문

createImageData() 메서드에는 두 가지 버전이 있습니다.

1. 이렇게 하면 지정된 치수(픽셀 단위)로 새 ImageData 객체가 생성됩니다.

자바스크립트 구문: var imgData = 컨텍스트 .createImageData( 너비, 높이 );

2. 이것은 anotherImageData에 의해 지정된 객체와 같은 차원을 가진 새로운 ImageData 객체를 생성합니다(이것은 이미지 데이터를 복사하지 않습니다):

JavaScript syntax: var imgData = context.createImageData(imageData);

매개변수 값

Parameter Description
width The width of the new ImageData object, in pixels
height The height of the new ImageData object, in pixels
imageData anotherImageData object

❮ 캔버스 개체