部分代码:
ctx = canvas.getContext('2d');
img1.onload = function(){
var expectWidth = this.naturalWidth;
var expectHeight = this.naturalHeight;
if(this.naturalWidth>this.naturalHeight&&this.naturalWidth>600){
expectWidth = 600;
expectHeight = 500;//expectWidththis.naturalHeight / this.naturalWidth;
}else if(this.naturalHeight>this.naturalWidth&&this.naturalHeight>600){
expectHeight = 600;
expectWidth = 500;//expectHeightthis.naturalWidth / this.naturalHeight;
}
canvas.width = expectWidth;
canvas.height = expectHeight;
ctx.drawImage(img1, 0, 0,expectWidth,expectHeight);
}
0 个回复