如何把我画的颜料的图像放回去?
How can put image back of paints which i drew?
我想做的东西类似于画图程序。
问题是当我画一些线时(不只是线。我画的所有东西都包含在这种情况下。),这些线只画回我在画之前输入的图像。
一开始以为是代码顺序问题。但事实并非如此。
我只想像画图程序一样在图像上画一些线条。
像这样:enter image description here
您可以使用 PGraphics 绘制到单独的 "layer" 中。
初始化实例后,您可以在 beginDraw()
/ endDraw()
中使用典型的绘图方法(如参考示例所示)。
唯一剩下的就是使用 save()
保存足够简单的最终图像
这里是 Examples > Basics > Image > 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");
}
}
我想做的东西类似于画图程序。 问题是当我画一些线时(不只是线。我画的所有东西都包含在这种情况下。),这些线只画回我在画之前输入的图像。
一开始以为是代码顺序问题。但事实并非如此。
我只想像画图程序一样在图像上画一些线条。 像这样:enter image description here
您可以使用 PGraphics 绘制到单独的 "layer" 中。
初始化实例后,您可以在 beginDraw()
/ endDraw()
中使用典型的绘图方法(如参考示例所示)。
唯一剩下的就是使用 save()
保存足够简单的最终图像这里是 Examples > Basics > Image > 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");
}
}