アップロードした画像をキャンバスに入れて操作したいです。
HTML:
<h2>Upload:</h2>
<input type="file" id="take-picture" accept="image/*">
<h2>Preview:</h2>
<p>
<canvas id="show-picture" style="background-color: aqua; height: 100px; width: 100px;" />
</p>
アップロード後に画像を処理するJavaScriptは次のとおりです。
takePicture.onchange = function (event) {
var files = event.target.files,
file;
if (files && files.length > 0) {
file = files[0];
processImage(file);
}
};
今 processImage-method で、画像をキャンバス内に保存する必要があります。
function processImage(file) {
// showImage(showPicture, file); //loading into a regular img-tag
var canvas = document.getElementById('show-picture');
var context = canvas.getContext('2d');
context.drawImage(file, 100, 100);
}
このファイルを img タグに入れることはできましたが、単純に描画することはできません。
何か案は?