我有2周的div裁剪图像到画布
<div id="image-orig">
<img src="image_example.jpg"/>
</div>
<div id="image-crop">
<canvas id="preview" style="width:548px;height:387px"></canvas>
</div>
image_example.jpg可以是任何尺寸的图像。
function updatePreview(c) {
if(parseInt(c.w) > 0) {
var orig = $("#image-orig img")[0];
var canvas = $("#image-crop canvas")[0];
var context = canvas.getContext("2d");
context.drawImage(orig,
c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff,
0,0,canvas.width,canvas.height
);
}
}
$(function(){
$('#image-orig img').Jcrop({
onSelect: updatePreview,
onChange: updatePreview,
aspectRatio : parseFloat($('#image-orig img').width()/$('#image-orig img').height())
});
});
coeff - 它的系数如果大小图像较大的div预览。
这就是问题: http://dbwap.ru/3725988.png
在第二个div(画布)。质量图像非常低。
找到解决
canvas.width = c.w*coeff;
canvas.height = c.h*coeff;
context.drawImage(orig,
c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff,
0,0,c.w*coeff,c.h*coeff
);
$(that.el).find("#ImageCode").attr('src', canvas.toDataURL());
$(that.el).find("#ImageCode").show();
我只是创建图像标签和复制从画布图像。
只是我需要做这个没有服务器端platdorms。 – RED
更新的解决方案(首先,确保在html5画布中设置图像平滑) – BumbleB2na
也许它的工作原理,但此解决方案仅适用于IE,Mozilla。我解决了我的问题。 – RED