Loading...
Logo
Processing Forum
Hello Everyone,

      I want to create a PGraphics off-screen then upload it to my server.   I am using the  Post To Web library.  The .php file is on the server and successfully receives an image of the current sketch when I use the code on line 19 (verified via ftp), but does not upload my PGraphics type when I use the code on line 17.  I really do not know what the 'g' in img.getBytes(g) is - any ideas?  

In the console I receive the following message:

java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(ImageIO.java:1457)
at javax.imageio.ImageIO.write(ImageIO.java:1565)
at org.seltar.Bytes2Web.ImageToWeb.getBytes(ImageToWeb.java:142)
at webApp.orderButton(webApp.java:790)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.callTarget(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at controlP5.Button.mouseReleased(Unknown Source)
at controlP5.Controller.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControlWindow.mouseEvent(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleMouseEvent(Unknown Source)
at processing.core.PApplet.dequeueMouseEvents(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
<p><b>Error:</b> File is empty!</p>





Copy code
  1.   String url = "http://myDomain.com/Upload.php"; 
  2.   
  3.   PGraphics pg = createGraphics(myX,myY,P2D);


  4.   pg.beginDraw();
  5.   pg.image(testImage,0,0,pg.width,pg.height);
  6.   pg.endDraw();

  7.   
  8.   img.setType(ImageToWeb.PNG);
  9.   
  10.   String subFolder = "subFolder";
  11.   String fileName = "fileName";
  12.   
  13.   img.post(subFolder,url,fileName,false,img.getBytes(pg)); // this is the problem line

  14.   // img.post(subFolder,url,fileName,false,img.getBytes(g));


Any help is appreciated.  Thanks everyone.

-aimless

Replies(4)

Alright,  I looked at the documentation again and the getBytes() function should simply accept a PGraphics type.  Perhaps this is a bug?  I was going to use the getBytesJPEG() and getBytesTIFF(), but alas, they are protected. :(

 byte[] getBytes(PGraphics src) 
          Get the given PGraphics bytearray
Alright, after many roundabout attempts, I tried changing the file type to .jpg in stead of .png and it worked flawlessly... I suspect that this is some sort of bug.  To summarize: 

Copy code

  1.   String url = "http://myDomain.com/Upload.php"; 
  2.   PGraphics pg = createGraphics(myX,myY,P2D);

  3.   pg.beginDraw();
  4.   pg.image(testImage,0,0,pg.width,pg.height);
  5.   pg.endDraw();

  6.   img.setType(ImageToWeb.JPG); // when this line is used there is no issue
  7.   // img.setType(ImageToWeb.PNG); // when this line is used the file is empty (error as described above)
  8.   
  9.   String subFolder = "subFolder";
  10.   String fileName = "fileName";
  11.   
  12.   img.post(subFolder,url,fileName,false,img.getBytes(pg));


It would be nice to be able to upload a .png (from a quality standpoint / support for an alpha channel) but I guess .jpg will work for now.  I hope this helps someone.

-aimless
Hey!

I'm sorry, but I can't see the problem right now, and I unfortunately don't have time to dig into it.. so I'm dumping my library work-folder here:  http://libraries.seltar.org/postToWeb/ - section 1b. 

Hopefully that can help you..

-seltar
Thanks for the response seltar,

   I looked around and I think that the issue is on line 142 of ImageToWeb.java.  I am by NO means a java expert and have no idea what could be wrong with that line, but I think that's where the exception was thrown.  I poked around the java documentation and tried using a few different methods, but the effort was akin to a kid operating a power plant - just pushing buttons...

  I found that the TIFF option still works just fine and I will just take the file size hit for now.  Although I am highlighting a problem, I must say that I am very grateful for this library and all the time you have put into it.  Many thanks!


-aimless