Hi,
prior to Processing 1 I was used to build a PImage from a ByteArrayInputStream in this way:
Code:
PImage tmp = tmp;
tmp = new PImage((BufferedImage)ImageIO.read(
new ByteArrayInputStream(img)));
Now I've noticed errors in my library with Processing 1.0.3 so I investigated and I found in PImage.java
Code:
public PImage(java.awt.Image img) {
if (img instanceof BufferedImage) {
BufferedImage bi = (BufferedImage) img;
width = bi.getWidth();
height = bi.getHeight();
pixels = new int[width * height];
WritableRaster raster = bi.getRaster();
raster.getDataElements(0, 0, width, height, pixels);
The last line causes for me a
java.lang.ClassCastException: [I
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:3
47)
at processing.core.PImage.<init>(PImage.java:182)
at it.lilik.capturemjpeg.CaptureMJPEG.run(CaptureMJPEG.java:317)
There's some error in this new implementation or it's my fault?
Now I've fixed forcing the old behavior
Code:
PImage tmp = null;
BufferedImage buffI = (BufferedImage)ImageIO.read(
new ByteArrayInputStream(img));
/*
* Bypass Default PImage costructur forceing
* a load like in Processing < 1.0
*
*/
//tmp = new PImage((BufferedImage)ImageIO.read(
// new ByteArrayInputStream(img)));
BufferedImage bi = (BufferedImage) buffI;
int width = bi.getWidth(null);
int height = bi.getHeight(null);
int[] pixels = new int[width * height];
PixelGrabber pg =
new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width);
try {
pg.grabPixels();
} catch (InterruptedException e) { }
tmp = new PImage(width,height);
tmp.loadPixels();
for (int i = 0; i < width * height; i++) {
tmp.pixels[i] = pixels[i];
}
tmp.updatePixels();