 |
Author |
Topic: Using p5 in standalone app (Read 1505 times) |
|
pbarry
|
Using p5 in standalone app
« on: Aug 6th, 2004, 11:38pm » |
|
Hi, I'm using p5 as just one of many additional jars in a social network visualization program. My main class makes a JFrame that has my class that extends BApplet as its only component. My program works fine inside eclipse, but when I try to export the code as a jar, I can no longer access any of the images (that are dynamically downloaded at runtime) through p5's loadImage. What seems to be happening is that all of a sudden, the getClass().getResource("...") calls inside BGraphics all return null whenever any resource is attempted to be gotten, even simply requesting the "." resource failed when I tried g.getClass().getResource() in my BApplet extending class (that works in eclipse too). Does anyone know what I need to do to the BGraphics object to enable it to grab my images into BImages? Any help would be greatly appreciated.
|
|
|
|
fjen
|
Re: Using p5 in standalone app
« Reply #1 on: Aug 7th, 2004, 2:06pm » |
|
can you supply some code that gives the same error? Quote:(that are dynamically downloaded at runtime) |
| loadImage(URL) or loadImage(file) ?
|
|
|
|
pbarry
|
Re: Using p5 in standalone app
« Reply #2 on: Aug 7th, 2004, 5:11pm » |
|
The images are downloaded to files via java's net stuff, since I want to cache them and not force a download every time the program runs. After they're downloaded, I'm trying to use loadImage(file). As for some test code, here's a far dumbed down applet that just tries to load in a picture file: public class ImageLoadingTestApplet extends BApplet { BImage bimage; void setup() { size(100,100); System.out.println("graphics.getClass().getResource(\".\") => "+g.getClass().getResource(".")); bimage = loadImage("test.jpg"); } void loop() { background(255); image(bimage, 10, 20); } } And my main method in a little Main class is this: public static void main(String[] args) { try { JFrame frame = new JFrame(); JPanel panel = new JPanel(); BApplet applet = new ImageLoadingTestApplet(); applet.init(); applet.start(); panel.setLayout(new BorderLayout()); panel.add(applet, BorderLayout.CENTER); frame.getContentPane().add(panel); frame.pack(); frame.setTitle("Test of loadImage"); frame.show(); applet.requestFocus(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } And this successfully runs from within eclipse, (that system.out.println prints out the 'bin' directory under my eclipse project), but when I export this to a jar (with the p5 jars in the classpath when I run it), it can't load the image (I've tried putting it in several different directories for p5 to find it in). The output is: prompt> java -jar SNB.jar graphics.getClass().getResource(".") => null could not load image test.jpg Error while running applet. java.lang.NullPointerException at BGraphics.flat_image(BGraphics.java:3211) at BGraphics.image(BGraphics.java:4202) at BApplet.image(BApplet.java:2765) at ImageLoadingTestApplet.loop(ImageLoadingTestApplet.java:21) at BApplet.nextFrame(BApplet.java:434) at BApplet.run(BApplet.java:369) at java.lang.Thread.run(Unknown Source) Is that enough detail? Thanks for the quick reply!
|
|
|
|
fjen
|
Re: Using p5 in standalone app
« Reply #3 on: Aug 7th, 2004, 6:54pm » |
|
same error for me (os-x, p 68, java 1.4+) ... funny. i'm quite sure i've been loading images from sketches run as .jar before. here is my workaround: "test.jpg" is placed next to the .jar "dummy.jpg" is inside the .jar (from where i can load images) Code: BImage bimage; void setup() { size(100,100); bimage = loadImageJAR("test.jpg"); } void loop() { background(255); image(bimage, 0, 0); } BImage loadImageJAR (String image_name) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image img = toolkit.getImage( image_name ); // dummy image from inside .jar// BImage dummy = loadImage("dummy.jpg"); try { PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true); if (grabber.grabPixels()) { dummy.width = grabber.getWidth(); dummy.height = grabber.getHeight(); dummy.pixels = (int []) grabber.getPixels(); } else { System.out.println("Error grabbing Pixels"); } } catch (InterruptedException e) { e.printStackTrace(); } return dummy; } |
| /F
|
« Last Edit: Aug 7th, 2004, 7:55pm by fjen » |
|
|
|
|
pbarry
|
Re: Using p5 in standalone app
« Reply #4 on: Aug 9th, 2004, 1:26am » |
|
THANKS SO MUCH!! If you're interested to see the project you helped out, check out http://patrickbarry.com/projects/ljnet/
|
|
|
|
|