Even if I answered the question more than half a year ago on the QA site, I was sad that no one saw it, so I will post it.
I want to read image data with Processing and make an arbitrary area transparent with an arbitrary amount of transparency.
The code is below. It is a tricky technique to extract the color of each pixel of the image, set the amount of transparency, and then draw each pixel. I use ellipse when drawing pixels, but you can also use rect or spot. .. When using spot, the transparency setting uses stroke instead of fill.
PImage img;
int imgWidth, imgHeight;
//Range you want to be transparent
int xstart = 100;
int xstop = 200;
int ystart = 50;
int ystop = 100;
//Permeation amount
int tpSet = 100;
void setup() {
size(480, 320);
img = loadImage("imgName");
imgWidth = img.width;
imgHeight = img.height;
noStroke();
smooth();
background(255);
frameRate(60);
}
void draw() {
background(255);
img.loadPixels();
for (int x =0; x<imgWidth; x++) {
for (int y=0; y<imgHeight; y++) {
//x,If y is the selected range, make it transparent.
color imgColor = img.get(x,y);
if(x>xstart && x<xstop && y>ystart && y<ystop){
fill(imgColor, tpSet);
}else{
fill(imgColor);
}
ellipse(x, y, 1, 1);//May be rect
}
}
}
Recommended Posts