我可以得到顶部、左侧、宽度、高度的位置,但我无法裁剪为警报显示。
<script>
$(document).ready(function(e) {
$("#crop").click(function(){
var canvas=document.getElementById("Mystore1");
var context=canvas.getContext("2d");
var top=$('#face').offset().top;
var left=$('#face').offset().left;
var width=$('#face').width();
var height=$('#face').height();
alert(top);
alert(left);
alert(width);
alert(height);
var imageSrc ='../../../Public/Pictures/Sample Pictures/Desert.jpg';
var imageObj=new Image();
imageObj.onload=function(){
context.drawImage(imageObj, top, left, width, height, top, left, width, height);
};
imageObj.src=imageSrc;
});
});
</script>