processing - 如何把我画的颜料的图像放回去?
问题描述
我想做的东西类似于绘画程序。问题是当我画一些线时(不仅仅是线。我画的所有东西都包括在这种情况下。),这些线只是在我画之前画出来的。
起初,我认为这只是代码顺序的问题。但事实并非如此。
我只想在图像上画一些线条,比如绘画程序。像这样:在此处输入图像描述
解决方案
您可以使用PGraphics绘制到单独的“层”中。初始化实例后,您可以在beginDraw()
/中使用典型的绘图方法endDraw()
(如参考示例所示)。
唯一剩下的就是保存最终图像,这很简单,使用save()
这是示例 > 基础 > 图像 > LoadDisplay的修改示例,它使用单独的 PGraphics 实例在拖动鼠标时进行绘制,并在s
按下键时保存最终图像:
/**
* Based on Examples > Basics > Image > Load and Display
*
* Images can be loaded and displayed to the screen at their actual size
* or any other size.
*/
PImage img; // Declare variable "a" of type PImage
// reference to layer to draw into
PGraphics paintLayer;
void setup() {
size(640, 360);
// The image file must be in the data folder of the current sketch
// to load successfully
img = loadImage("moonwalk.jpg"); // Load the image into the program
// create a separate layer to draw into
paintLayer = createGraphics(width,height);
}
void draw() {
// Displays the image at its actual size at point (0,0)
image(img, 0, 0);
// Displays the paint layer
image(paintLayer,0,0);
}
void mouseDragged(){
// use drawing commands between beginDraw() / endDraw() calls
paintLayer.beginDraw();
paintLayer.line(mouseX,mouseY,pmouseX,pmouseY);
paintLayer.endDraw();
}
void keyPressed(){
if(key == 's'){
saveFrame("annotated-image.png");
}
}
推荐阅读
- java - 选择联系人java android时获取电子邮件列索引
- ocaml - 为什么使用 _ 防止出现警告
- mysql - 我将如何使用 nodejs sequelize 执行此 SQL 查询?
- vuex - 将数据从组件发送到 Vuex
- google-apps-script - 如何根据第 1 列中的值将行从工作表 x 复制(然后删除)到工作表 y?
- python - 为什么 Python 列表没有连续重复元素的唯一索引?
- php - 内部foreach循环检查条件并仅中断php中的内部循环
- hybris - 查找 SAP Hybris 依赖项的版本
- c# - 如何在插入失败时获取冲突行的主键?
- sql - 如何从 postgres 函数返回两个 SELECT 语句的结果?