Pages: [1]   Go Down
Author Topic: Writing image file (png, jpg) to SD card?  (Read 836 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
..::..::..::..
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Possible?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31543
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
..::..::..::..
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
..::..::..::..
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 -

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: