We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to do a simple alpha blending of two images.
It runs fine in JAVA mode but crashes on my Android device when I try to run on device.
Seems the line reponsible for the crash is the imgB.set() command.
If I comment that out, it runs without crashing.
My images are 1920x1080 but I've tried smaller images and it doesn't help.
Wondering if maybe the bitmap is nonmutable (i.e. can't be written to).
PImage imgA, imgB;
void setup() {
size(1920, 1080);
imgA = loadImage("blendA.png");
imgB = loadImage("blendB.png");
for (int y = 0; y < imgB.height; y++) {
for (int x = 0; x < imgB.width; x++) {
color c = imgB.get(x,y);
color d = color(red(c), green(c), blue(c), 128); // set alpha
imgB.set(x,y,d);
}
}
}
void draw() {
background(imgA);
blend(imgB, 0, 0, 1920, 1080, 0, 0, 1920, 1080, BLEND);
}
FATAL EXCEPTION: Animation Thread Process: processing.test.sketch_blend, PID: 27836 java.lang.IllegalStateException at android.graphics.Bitmap.setPixel(Bitmap.java:1509) at processing.core.PImage.set(Unknown Source) at processing.test.sketch_blend.sketch_blend.setup(sketch_blend.java:31) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:841)
Any help appreciated!!!
Thanks, Ike
Comments
@ikizyan:: i think that you are right: your imgA &B are supposed to be immutable; in this case you have to create some third image with createImage(). See the code below: i have tried and it works (with little pictures but i presume also with big ones). Think also that using background(image) supposes that the size of the image = the size of your sketch and that android ignores size().
Dear akenaton,
Your code modifications worked for me!!! Thank you much!
-Ike