problem with get()
in
Programming Questions
•
7 months ago
Hy hello
i am a complete beginner with processing. However i achieved a short code that works well using get().
When trying the same code with another computer, i get an error, on the line using get() :
Exception in thread "Animation Thread" java.lang.ClassCastException: [I cannot be cast to [S
at sun.awt.image.ShortInterleavedRaster.getDataElements(ShortInterleavedRaster.java:228)
at processing.core.PGraphicsJava2D.get(PGraphicsJava2D.java:2357)
at processing.core.PApplet.get(PApplet.java:15049)
at sketch_130319a.setup(sketch_130319a.java:30)
at processing.core.PApplet.handleDraw(PApplet.java:2241)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2140)
at java.lang.Thread.run(Thread.java:662)
here is the code :
size(500,116);
PImage hetre = loadImage("hetre 04.jpg");
hetre.filter(GRAY);
hetre.resize(0,116);
image(hetre,0,0);
noSmooth();
float a = 220;
float b = 180;
float c = 140;
float d = 100;
for (int i = 1; i<width ; i=i+1) {
for (int j = 1; j<height ; j=j+1) {
float g = red(get(i,j));
if (g>a) {
stroke(255);
point(i,j);
}else if ((b<g) && (g<(a+1))) {
stroke(200);
point(i,j);
}else if ((c<g) && (g<(b+1))) {
stroke(100);
point(i,j);
}else if ((d<g) && (g<(c+1))) {
stroke(50);
point(i,j);
}else {
stroke(0);
point(i,j);
}
}}
image(hetre,0,0);
save("hetre2.png");
Thank you for your help.
Rémi
1