技術情報
[08] canvasに描画した画像をimgタグに割り当てる
[コード例]
[imgタグ]<br>
<div style="border: 1px dotted #000000; width:400px; height:200px">
<img id="sample" width="400" height="200"><br>
</div>
[canvas]<br>
<canvas id="can" width="400" height="200"></canvas><br>
<form>
<input type="button" onClick="myFunc()" value="割当">
</form>
<script>
var can = document.getElementById("can");
var ct = can.getContext('2d');
ct.beginPath();
ct.fillStyle = '#ff0000';
ct.fillRect(50, 10, 300, 50);

function myFunc()
{
var url = can.toDataURL();
document.getElementById("sample").src = url;
}
</script>

[表示例]
[imgタグ]

[canvas]