簡體   English   中英

如何調整上傳圖像到 canvas 的大小

[英]how to resize uploading image on to canvas

我在嘗試將上傳的圖像調整到項目的 html 時遇到問題。 當我尋找解決方案時。 網站https://www.w3schools.com/tags/canvas_drawimage.asp給了我一個想法,但我似乎無法理解腳本。 我對劇本有誤解嗎?

<javascript>    
function uploadForegroundImage(){
fileInput = document.getElementById("foregroundImageUpload");
image = new Image(fileInput);
image.onload = function() {
   var c = document.getElementById("foregroundImageCanvas");
   var ctx = c.getContext("2d");
   var img = document.getElementById(fileInput);
   ctx.drawImage(img, 10, 10, 600, 400);
  }
 }
</javascript>

提供的代碼應該可以工作。 如果您遇到錯誤,請確保從您有權訪問的 URL 或 select 使用 HTML 輸入標簽加載它。 另外我不知道“javascript”標簽,它應該改為“腳本”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM