Writing image file (png, jpg) to SD card?

Has anyone looked into/had success writing image files using the Arduino, preferably to an SD card? I don't need high resolution at all or to write the file quickly.

Some possible (but confusing) starting points: + http://www.jpegcameras.com/libjpeg/libjpeg.html + http://pngwriter.sourceforge.net


The big question is where are you going to get the data of the image from? Writing to an SD card is no problem but the arduino has very little memory to store even a part of an image. Most image sources like JPEG cameras need the data to be transferred out of them quickly, much quicker than you can write them to an SD card.

Hi Grumpy_Mike, sorry - I should have been a little more detailed:

I'm basically making a super low-resolution digital camera using light-sensitive resistors. The "preview screen" is an array of LEDs. The total number of pixels will likely be around 9 or 12. The whole project will hopefully fit inside an old 35mm SLR camera, using the camera's lens.

I'd like to have the system be completely self-contained, so writing an image file is a lot better than the simple solution I have now (writing ASCII values to a .txt file and post-processing using Processing).

Compressed image formats such as JPEG and PNG would require far too much code support to fit practically on to an Arduino; with so few pixels you'd be better off with an uncompressed format like BMP or Netpbm. Support for the latter's images is more common on UNIX-derived systems, but I'm sure you'd be able to find Windows software to open or convert them.

Netpbm's PGM and PPM have ASCII encodings which are incredibly simple. They're really just text files arranged in particular ways.

BMP is pretty basic but more binary-oriented - but should open in pretty much anything.

Good luck!

I was thinking a BMP might be lighter-weight... didn't consider the Wikipedia page would have such a detailed explanation! Never heard of PGM before - seems hard to convert to any other format without a plugin, so BMP might be the way to go.

I'll have to do some more research on writing binary files. Suggestions for good (and simple) tutorials to look at?

for pgm there are very good toolkits linux: - http://linux.about.com/library/cmd/blcmdl1_netpbm.htm - windows: - http://gnuwin32.sourceforge.net/packages/netpbm.htm -

While I haven't (yet) done it with an Arduino, I've had quick, hacky scripts generate BMP files by printing a predefined header then spamming out the necessary pixel data.

One way to get the header is to save an appropriately-dimensioned file in a graphics program. (The GIMP's pretty good for saving BMPs with particular colour depths and so on.) For a greyscale image, each pixel takes one byte - so for a 10x10 image, take the file size and subtract 100 from it. The resulting number of bytes at the beginning of the file is the header. Store that data in an array or something; saving an image on the Arduino would then involve outputting the header and then a byte for each pixel, starting with the bottom-left pixel and scanning from left to right. (Most other image formats start at the top-left.)

While it doesn't let you change image parameters, it involves incredibly little code - and on an Arduino, makes much more sense than somehow squeezing in a full-featured image library.

Guys is it possible to take image from Android phone to arduino through UART and as each byte is received can we save it to SD card?? And then read the image from SD card??