P5.js-有没有办法切出图像区域? [英] P5.js - Is there a way to cut out an image area?

查看:162
本文介绍了P5.js-有没有办法切出图像区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以裁剪"一张图像并将其与P5.js库一起使用?

Is there a way to "cut out" a piece of image and use it with the P5.js library?

示例:假设我有一张尺寸为100x100的图像,但需要获取一个从像素50,50开始的10x10像素切口

Example: Lets say I have a image of the size 100x100 but need to get a 10x10 pixel cutout that starts at pixel 50,50

我想拍摄生成的10x10图像,并使用 image(result,X,Y,10,10)放置在任何地方.

I want to take the resulting 10x10 image and place it anywhere with image(result, X, Y, 10, 10).

注意: 我唯一可以在网上找到与此类似的东西是使用 mask(),但结果不是我所需要的.

Note: The only thing I could find online similar to this was using mask() but the result is not what I need.

推荐答案

深入研究内部,并得到P5ers的帮助,我发现解决方案是:

After a deeper look inside, and help from fellow P5ers I figured out that the solution is:

P5.js中的 GET()方法

The GET() method from P5.js

https://p5js.org/reference/#/p5/get

可以根据需要使用get()方法:get(startX,startY,width,height)并返回可以根据需要保存或使用的图像.

The get() method can be used as needed: get(startX, startY, width, height) and returns and image that can be saved or used as needed.

这篇关于P5.js-有没有办法切出图像区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆