We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › writing an image from data
Page Index Toggle Pages: 1
writing an image from data (Read 312 times)
writing an image from data
Dec 29th, 2007, 10:32pm
 
Is there a way to convert an array/matrix of numbers to a bitmap or jpeg?
Re: writing an image from data
Reply #1 - Dec 29th, 2007, 11:29pm
 
Yes, fairly easily.

Code:
//asuming your numbers stored in an array called myInts

PImage img=new PImage(newWidth,newHeight);
for(int i=0;i<myInts.length;i++)
{
img.pixels[i]=myInts[i]; //assuming they're already in ARBG format
}
img.updatdPixels();
image(img,0,0);
saveFrame("myimage.jpg");


If your numbers are just a simple value and you want it to be greyscale you need to change the img.pixels[i]= line to something like:

Code:
int pixel=(myInts[i]<<16)+(myInts[i]<<8)+myInts[i];
img.pixels[i]=pixel;
Page Index Toggle Pages: 1