【发布时间】:2018-11-11 00:35:02
【问题描述】:
我研究并发现您可以使用get()“裁剪”图像,但是必须在屏幕上绘制图像,然后在其中截取画布的一部分。是否可以加载图像然后将其裁剪版本保存在变量中?所以可能是这样的:
var img;
var cropped;
function preload(){
img = imageLoad('dog.png', crop)
}
function crop(image){
cropped = crop(img, 0, 0, img.w/2, img.h) // Getting left half of image
}
谢谢。
编辑: 这是我使用 copy() 制作的函数,但我不知道我是否缺少更简单的方法。
function crop(image, x, y, w, h) {
var cropped = createImage(w, h);
cropped.copy(image, x, y, x + w, y + h, 0, 0, x + w, y + h)
return cropped;
}
【问题讨论】:
-
这是什么
crop()函数?我很确定您的代码会导致堆栈溢出。 -
这是伪代码,一个例子。
标签: javascript image crop p5.js