Git Product home page Git Product logo

Comments (6)

jeffThompson avatar jeffThompson commented on June 6, 2024

Not having my tablet in front of me, I believe the error might be with you accessing the image's pixels. While you can do this the way you have it in the desktop version, if memory serves the Android mode will cause an NPE if you don't include img.loadPixels() and img.updatePixels() first.

from processing-android-archive.

xstreck1 avatar xstreck1 commented on June 6, 2024

I have chosen the example so no external file is needed, however if the image is created using the loadImage() method (and pixels are not accessed), the crash occurs as well. E.g. extension of the LoadDisplayImage example:

PImage img;  // Declare variable "a" of type PImage

void setup() {
  size(640, 360);
  // The image file must be in the data folder of the current sketch 
  // to load successfully
  img = loadImage("moonwalk.jpg");  // Load the image into the program  
  img.resize(100,100);
}

void draw() {
  // Displays the image at its actual size at point (0,0)
  image(img, 0, 0);
  // Displays the image at point (0, height/2) at half of its size
  image(img, 0, height/2, img.width/2, img.height/2);
}

crashes with:
FATAL EXCEPTION: Animation Thread
java.lang.NullPointerException
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.PApplet.image(Unknown Source)
at processing.test.loaddisplayimage.LoadDisplayImage.draw(LoadDisplayImage.java:41)
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)

But, actually, based on your suggestion I have tried adding pixel manipulation methods to the code and the following version (img.loadPixels() is added after resize) works:

PImage img;  // Declare variable "a" of type PImage

void setup() {
  size(640, 360);
  // The image file must be in the data folder of the current sketch 
  // to load successfully
  img = loadImage("moonwalk.jpg");  // Load the image into the program  
  img.resize(100,100);
  img.loadPixels();
}

void draw() {
  // Displays the image at its actual size at point (0,0)
  image(img, 0, 0);
  // Displays the image at point (0, height/2) at half of its size
  image(img, 0, height/2, img.width/2, img.height/2);
}

I am not familiar with method Processing internally works with images, but I assume that the requirement the explicit call of img.loadPixels() is not intentional.

from processing-android-archive.

GKFX avatar GKFX commented on June 6, 2024

Duplicate of #22.

from processing-android-archive.

PandaBalls avatar PandaBalls commented on June 6, 2024

why it is closed ? i didn't find the solution for this resize() problem. i just got the same issue.

from processing-android-archive.

GKFX avatar GKFX commented on June 6, 2024

It's not really closed as in fixed, it's closed as a duplicate. The report is still open at #22.

from processing-android-archive.

GKFX avatar GKFX commented on June 6, 2024

Actually, it's processing/processing-android#21; this repository is archived.

from processing-android-archive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.