사용자 지정 도형에서 이미지의 마스크를 만들려고합니다. 처리에서 나는이 함께했다 : 코드 위다각형 (처리)에서 마스크를 만드는 방법은 무엇입니까?
Image img;
PImage img2;
PGraphics mGraphic;
void setup(){
img = loadImage("mask.jpg");
img2 = loadImage("test.jpg");
mGraphic = createGraphics(1024,1024, JAVA2D);
size(img.width, img.height);
}
void draw(){
background(255);
mGraphic.beginDraw();
mGraphic.background(0);
mGraphic.ellipse(mouseX, mouseY, 400, 400);
mGraphic.endDraw();
img2.mask(mGraphic);
image(img2,0,0);
}
이미지의 마스크있을 것 타원을 작성합니다. The method mask(int[]) in the type PImage is not applicable for the arguments (Masking_image_1.CustomShape)
은 처음과 같은 결과를 얻을이 가능하다조차 :
import java.awt.Polygon;
PImage img;
PImage img2;
PGraphics mGraphic;
CustomShape myShape = new CustomShape();
void setup(){
img = loadImage("mask.jpg");
img2 = loadImage("test.jpg");
mGraphic = createGraphics(1024,1024, JAVA2D);
myShape.addPoint(25, 25);
myShape.addPoint(275, 25);
myShape.addPoint(275, 75);
myShape.addPoint(175, 75);
myShape.addPoint(175, 275);
myShape.addPoint(125, 275);
myShape.addPoint(125, 75);
myShape.addPoint(25, 75);
smooth();
// img2.filter(INVERT);
size(img.width, img.height);
}
void draw(){
background(255);
stroke(0);
myShape.display();
img2.mask(myShape);
image(img2,0,0);
}
class CustomShape extends Polygon {
void display() {
stroke(0);
fill(0);
beginShape();
for (int i=0; i<npoints; i++) {
vertex(xpoints[i], ypoints[i]);
}
endShape(CLOSE);
}
}
불행하게도,이 코드는 나에게 오류를 줄 것이다 : 나는 다각형에 의해 생성 된 사용자 정의 모양으로 동일한을 달성하고자하는 코드를 사용하지만 사용자 정의 모양을 사용하면됩니까? 어떻게 해결할 수 있을까요?
질문이 있으면 알려 주시기 바랍니다. 위 코드는 Processing 내부에서 작동합니다.