PImage outImage;
void setup()
{
int w = 640;
int h = 480;
int ch = 3; //colour channels per pixel
//this is what you would get from you micro-controller
//you have to know the dimensions and what colour format it has
//i.e. greay scale ch=1 or RGB = 3, or with alpha transparency ch = 4
byte[] imageFromMBED = new byte[w*h*ch];
outImage = ByteArrayToImage(imageFromMBED, w, h, ch);
outImage.save("image.jpg"); //done!
}
void draw()
{
//display result
image(outImage,0,0);
}
PImage ByteArrayToImage(byte[] data, int w, int h, int ch)
{
//make a new image
PImage outImage = new PImage(w,h,RGB);
//copy date to this new image
outImage.loadPixels();
for(int i = 0; i < w*h; i++)
{
outImage.pixels[i] = color(data[i*ch],data[i*ch+1],data[i*ch+2]);
}
outImage.updatePixels();
return outImage;
}
www.morishuz.com
www.videoreactive.com
www.electrovision-cinema.com