【发布时间】:2012-08-12 16:41:37
【问题描述】:
我在http://yc.sg/fantaspic/compare.html 做了一个快速示例。它很丑,只是为了功能。它使用 FileAPIs,没有任何东西可以发送到服务器端,所以请随意尝试使用任何照片:P。好的,要使用它,只需浏览,选择一张照片并单击确定,然后裁剪即可。
左下角的图像是使用 HTML 5 画布重绘的(以原始图像为源),而右下角的图像只是一个 div,原始图像被四处移动。画布图像总是导致质量较低,尽管它只是一个简单的裁剪。
您可以查看源代码并了解它是如何工作的,但主要的裁剪方法是这样的:
function preview(img, selection) {
var scaleX = previewWidth / selection.width;
var scaleY = previewHeight / selection.height;
$('#cropped-image').css({
width: Math.round(scaleX * truew) + 'px',
height: Math.round(scaleY * trueh) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
selx1 = selection.x1;
sely1 = selection.y1;
selx2 = selection.x2;
sely2 = selection.y2;
selw = selection.width;
selh = selection.height;
var canvas = $("#preview")[0];
var context = canvas.getContext("2d");
context.drawImage(img, selx1, sely1, selw, selh, 0, 0, canvas.width, canvas.height);
}
【问题讨论】:
-
我看不出有什么不同。 OSX、Opera