我想將上傳的圖片放入canvcas中以使用它。將原始圖像繪製到畫布中
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來法的圖片應該存儲在一個畫面內。
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-tag中,但我不能簡單地繪製它。
你能幫我嗎?
但我沒有任何圖像源 –
如果您可以通過HTTP連接到該圖像:// yourhost /路徑到影像,您可以使用它在JavaScript中作爲...... var img = new Iamge(); img.src =的 'http:// yourhost /路徑到圖像'; img.onload = ...... – benbai123