我想在java脚本中拍摄一部分图像并将其转换为新图像,如下所示:
var image2 = new Image();
image2.src = image1.src(10,10)
显然上面的内容不会起作用,但是会怎样?,例子很受欢迎,
编辑:我想在绘制它之前裁剪它
谢谢。答案 0 :(得分:1)
如何从另一个人制作图像。
// img1 is the first img
var canvas = document.createElement("canvas");
canvas.width = 10; // size of new image
canvas.height = 10;
var ctx = canvas.getContext("2d"); // get the context
// draw part of the first image onto the new canvas
ctx.drawImage(img1,0,0,10,10,0,0,10,10);
// create a new image
var imgNew = new Image();
// set the src from the canvas
imgNew.src = canvas.toDataURL();