var imageWidth = canvas.width / Math.sqrt(scale);
var imageHeight = canvas.height / Math.sqrt(scale);
var sx = (canvas.width-imageWidth)/2;
var sy = (canvas.height-imageHeight)/2;
context.drawImage(image,sx,sy,imageWidth,imageHeight,0,0,canvas.width,canvas.height);
var imageHeight = canvas.height / Math.sqrt(scale);
var sx = (canvas.width-imageWidth)/2;
var sy = (canvas.height-imageHeight)/2;
context.drawImage(image,sx,sy,imageWidth,imageHeight,0,0,canvas.width,canvas.height);
2016-11-03
原图应该按image.width和image.height来设置,目标画布大小按imagewidth,和imageheight来设置,具体怎么解释我也解释不好,反正我是试出来了。
ps:第二种方法是没问题的。
ps:第二种方法是没问题的。
2016-10-26
function drawImageByScale(scale){
var imagewidth=600*scale;
var imageheight=400*scale;
var Sx=imagewidth/2-canvas.width/2;
var Sy=imageheight/2-canvas.height/2;
context.drawImage(image,Sx,Sy,image.width,image.height,0,0,imagewidth,imageheight);
}
这样就对了。
var imagewidth=600*scale;
var imageheight=400*scale;
var Sx=imagewidth/2-canvas.width/2;
var Sy=imageheight/2-canvas.height/2;
context.drawImage(image,Sx,Sy,image.width,image.height,0,0,imagewidth,imageheight);
}
这样就对了。
2016-10-26
cantext.drawImage(image,sx,sy,canvas.width,canvas.height,0,0,canvas.width,canvas.height)
是不对的。
是不对的。
2016-10-26
var offCanvas = document.createElement('canvas');
var offContext = offCanvas.getContext('2d');
也可以
var offContext = offCanvas.getContext('2d');
也可以
2016-10-26