Thanks Quarks !! It does work very well under java mode !
I try to implement it under android and there's a problem because android doesn't support javax.imageio and awt buffered image…
Images seem to load correctly, ( "queue complete") the problem occurs when trying to read buffered images…
would it be possible to replace those functions by another ones which would do the same job ?
I try to do that with Bitmap and BitmapFactory from android, but I still get errors:
- /**
DataBuffer taken from http://wiki.processing.org/w/Asynchronous_data/image_loading
@author toxi
*/
import java.io.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
//import javax.imageio.*;
//import java.awt.image.BufferedImage;
import processing.core.PConstants;
import processing.core.PImage;
public class DataBuffer {
private byte[] bytes;
public DataBuffer(byte[] buf) {
bytes=buf;
}
public byte[] getRaw() {
return bytes;
}
public String getAsText() {
return getAsText("UTF-8");
}
public String getAsText(String encoding) {
try {
return new String(bytes, encoding);
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
// updated according to:
// http://forum.processing.org/topic/converting-bufferedimage-to-pimage#25080000000340208
public PImage getAsImage() {
try {
ByteArrayInputStream bis=new ByteArrayInputStream(bytes);
Bitmap bimg = BitmapFactory.decodeStream(bis);
PImage img=new PImage(bimg.getWidth(), bimg.getHeight(), PConstants.ARGB);
bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);
img.updatePixels();
return img;
}
catch(Exception e) {
System.err.println("Can't create image from buffer");
e.printStackTrace();
}
return null;
}
}
It gives me :
[javac] symbol : method getRGB(int,int,int,int,int[],int,int)
[javac] location: class android.graphics.Bitmap
[javac] bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);
[javac] ^
[javac] 1 error
BUILD FAILED
/Developer/Applications/adt-bundle-mac-x86_64/sdk/tools/ant/build.xml:710: The following error occurred while executing this line:
/Developer/Applications/adt-bundle-mac-x86_64/sdk/tools/ant/build.xml:723: Compile failed; see the compiler error output for details.
Total time: 5 seconds
processing.app.SketchException: cannot find symbol
at processing.mode.java.JavaBuild.placeException(JavaBuild.java:687)
at processing.mode.android.AndroidBuild.antBuildProblems(AndroidBuild.java:464)
at processing.mode.android.AndroidBuild.antBuild(AndroidBuild.java:433)
at processing.mode.android.AndroidBuild.build(AndroidBuild.java:73)
at processing.mode.android.AndroidMode.handleRunDevice(AndroidMode.java:218)
at processing.mode.android.AndroidEditor$14.run(AndroidEditor.java:310)
I can't find the equivalent with Bitmap.
thanks in advance
.pauline.