I have a canvas of size 300px to 300px and I drag and drop a very large image on to it. so it takes the size of the canvas. Then I have a resizable and moveable square which I use to crop certain areas. So using jquery I take the width and height of the crop square and the x and y distance to the clipping point. But when I finally crop and display the region in a second canvas I can see that the cropped region is not exactly what I selected as the region to be cropped.
I dont want to use getimagedata and putimagedata commands. I want to use drawimage command only
Please help
var x = $("#crop_square").width();
var y = $("#crop_square").height();
var ty = $("#crop_square").offset().top - $("#area_c").offset().top;
var tx = $("#crop_square").offset().left - $("#area_c").offset().left;
var c = document.getElementById("area_c");
var c2 = document.getElementById("area_c2");
var ctx = c.getContext("2d");
var ctx2 = c2.getContext("2d");
ctx2.drawImage(image_src,tx,ty,x, y,0,0,c2.width,c2.height);
<canvas id ="area_c" style="width:300px;height:300px;border:3px solid black;z-index:1" ondrop="dropb(event)" ondragover="myfkb(event)" >
</canvas>
<canvas id ="area_c2" style="width:300px;height:300px;border:3px solid black;z-index:1" >
</canvas>