PImage resize function not working in android mode

edited October 2013 in Android Mode

Hi, When i try the resize() function in the android mode, it gives me the following error

FATAL EXCEPTION: Animation Thread
        at android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:834)
        at android.graphics.Bitmap.setPixels(Bitmap.java:892)
        at processing.core.PGraphicsAndroid2D.imageImpl(Unknown Source)
        at processing.core.PGraphics.image(Unknown Source)
        at processing.core.PGraphics.image(Unknown Source)
        at processing.core.PApplet.image(Unknown Source)
        at processing.test.the_timetable.The_timetable$Lecture.draw_normal_state(The_timetable.java:699)
        at processing.test.the_timetable.The_timetable$Lecture.draw_lecture(The_timetable.java:670)
        at processing.test.the_timetable.The_timetable$Day.draw_day(The_timetable.java:506)
        at processing.test.the_timetable.The_timetable$Week.draw(The_timetable.java:1740)
        at processing.test.the_timetable.The_timetable.draw(The_timetable.java:67)
        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:1019)

I think that resizing the image using the method image(x, y, width, height) is horrible because it drops the frame rate down to about 10 fps on my android device, and this ruins the app.

How can i resize the image once ?


  • Instead of resizing it with processing ,how about you use a larger or smaller version of the image ...for instance you can resize it with microsoft office before you import to Processing but you should note though, you can't have a constant image size if you intend to run your application on different android devices because different devices have different screen sizes

  • edited October 2013

    Hi, you could resize all the images you want by doing something like this:

    scale(Scale.scaleWidth, Scale.scaleHeight);
    image(pImage, x, y, originalWidth, originalHeight);
    //images that should be scaled
    //images that shouldn't be scaled
  • Matrix push / pops and transformations are generally really bad for the framerate as well, which goes against the poster's original intentions...

  • Are you sure? I thought that it was a good practice in opengl the use of matrix transformations

  • edited October 2013

    Perhaps in OpenGL, but that isn't Processing's default renderer in either Java or Android mode. In general, transformations kill performance when using Java2D.... at least in my experience.

  • I got the same problem and found a walk-around of resize() in the android mode. That's using copy() method.

    I agree that using image(x,y,width,height) in draw() function induces a huge overhead. I think it's always better to have resized PImage at your setup(). Try this:

    PImage tmp;
    PImage photo1;
    PImage photo2;
    void setup() {
    tmp = loadImage("photo1.png");
    photo1 = new PImage(targetW, targetH);
    photo1.copy(tmp, 0, 0, tmp.width, tmp.height, 0, 0, targetW, targetH);
    // You can reuse 'tmp'
    tmp = loadImage("photo2.jpg");
    photo2 = new PImage(targetW2, targetH2);
    photo2.copy(tmp, 0, 0, tmp.width, tmp.height, 0, 0, targetW2, targetH2);
  • example..

    img.resize(400, 400); img.loadPixels(); ////insert this!!


  • [code] img.resize(400, 400); img.loadPixels();////insert this [/code]

  • Camperos you are, simply, the fucking boss<3

  • use in the following order and it will work. image.loadPixels(); image.resize(targetW,targetH); image.updatePixels();

Sign In or Register to comment.