context . createImageData(imagedata) …… ImageDataオブジェクトを生成する
![Internet Explorer9](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_i9.gif)
![Firefox2](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f2.gif)
![Firefox3](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f3.gif)
![Firefox4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f4.gif)
![Google Chrome2](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc2.gif)
![Google Chrome3](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc3.gif)
![Google Chrome4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc4.gif)
![Google Chrome5](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc5.gif)
![Google Chrome6](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc6.gif)
![Safari4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_s4.gif)
![Safari5](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_s5.gif)
![Opera9](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_o9.gif)
![Internet Explorer9](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_i9.gif)
![Firefox2](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f2.gif)
![Firefox3](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f3.gif)
![Firefox4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_f4.gif)
![Google Chrome2](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc2.gif)
![Google Chrome3](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc3.gif)
![Google Chrome4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc4.gif)
![Google Chrome5](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc5.gif)
![Google Chrome6](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_gc6.gif)
![Safari4](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_s4.gif)
![Safari5](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_s5.gif)
![Opera9](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_o9.gif)
![Opera10](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/b_o10.gif)
広告
createImageData(imagedata)メソッドは、
元になるImageDataオブジェクトと同じ寸法のImageDataオブジェクトを生成する際に使用します。
引数imagedataは、元になるImageDataオブジェクトを表します。
生成される新規ImageDataオブジェクトは透明な黒となります。
■引数(値)の説明
- imagedata
- 元になるImageDataオブジェクト
■使用例
HTML + JavaScriptソース
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvasで図形を描く</title>
<script type="text/javascript">
<!--
function test() {
//描画コンテキストの取得
var canvas = document.getElementById('sample');
if (canvas.getContext) {
var context = canvas.getContext('2d');
//寸法100×80のImageDataオブジェクトを生成
var img01 = context.createImageData(100, 80);
//img01と同じ寸法のImageDataオブジェクトを生成
var img02 = context.createImageData(img01);
//ImageDataオブジェクトの幅をテキストとして描画
context.fillText(img02.width, 20, 75);
}
}
//-->
</script>
</head>
<body onLoad="test()">
<h2>Canvasで図形を描く</h2>
<canvas width="300" height="150" id="sample" style="background-color:yellow;">
図形を表示するには、canvasタグをサポートしたブラウザが必要です。
</canvas>
</body>
</html>
↓↓↓
ブラウザ上の表示
Canvasで図形を描く
■関連項目
<canvas> …… 図形を描く
![HTML5から追加](https://htmqcom1.wpengine.com/wp-content/uploads/2024/07/html5add.gif)
広告