第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用javascript畫布調(diào)整圖像大?。樌?/h1>

使用javascript畫布調(diào)整圖像大?。樌?/h1>
使用javascript畫布調(diào)整圖像大小(順利)我試圖用帆布調(diào)整一些圖像的大小,但我對如何平滑它們毫無頭緒。在Photoshop,瀏覽器等..他們使用了一些算法(例如雙三次,雙線性)但我不知道它們是否內(nèi)置于畫布中。這是我的小提琴:http://jsfiddle.net/EWupT/var canvas = document.createElement('canvas');var ctx = canvas.getContext('2d');canvas.width=300canvas.height=234ctx.drawImage(img, 0, 0, 300, 234);document.body.appendChild(canvas);第一個是普通的已調(diào)整大小的圖像標(biāo)記,第二個是畫布。請注意畫布如何不那么平滑。我怎樣才能實現(xiàn)'順暢'?
查看完整描述

3 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗 獲得超12個贊

由于Trung Le Nguyen Nhat的小提琴根本不正確(它只是在最后一步使用了原始圖像),
我寫了自己的一般小提琴,進(jìn)行了性能比較:

小提琴

基本上它是:

img.onload = function() {
   var canvas = document.createElement('canvas'),
       ctx = canvas.getContext("2d"),
       oc = document.createElement('canvas'),
       octx = oc.getContext('2d');

   canvas.width = width; // destination canvas size
   canvas.height = canvas.width * img.height / img.width;

   var cur = {
     width: Math.floor(img.width * 0.5),
     height: Math.floor(img.height * 0.5)
   }

   oc.width = cur.width;
   oc.height = cur.height;

   octx.drawImage(img, 0, 0, cur.width, cur.height);

   while (cur.width * 0.5 > width) {
     cur = {
       width: Math.floor(cur.width * 0.5),
       height: Math.floor(cur.height * 0.5)
     };
     octx.drawImage(oc, 0, 0, cur.width * 2, cur.height * 2, 0, 0, cur.width, cur.height);
   }

   ctx.drawImage(oc, 0, 0, cur.width, cur.height, 0, 0, canvas.width, canvas.height);}


查看完整回答
反對 回復(fù) 2019-08-26
  • 3 回答
  • 0 關(guān)注
  • 1084 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號