On Mar 23, 7:26 pm, Gregory Seidman <gsslist
+
iphone...@anthropohedron.net> wrote:
> On Mon, Mar 23, 2009 at 04:37:07PM -0400, Patrick Kedziora wrote:
> > I want to display questions and solutions that have text and images and want
> > to store them in a SQL lite database. What is the best way to do this?
>
> You almost certainly do not want to store images in the database when you
> have access to a filesystem. If you have all the text and images a priori
> (i.e. they are to be shipped in the app bundle), just store the names of
> the images and use [UIImage imageNamed:]. If you are retrieving them from
> the web or getting them from the user, I recommend using
> UIImagePNGRepresentation() and storing it with a GUID for the filename
> under the ~/Documents directory, then saving that name in the database. You
> can retrieve it with [UIImage imageWithContentsOfFile:].
>
There are certain situations where it might be advantageous to store
images within the SQLite database, so that you only have to manage a
single file, rather than multiple ones across a filesystem. I provide
an example of saving a PNG representation of an image in SQLite as a
binary BLOB on Stack Overflow:
http://stackoverflow.com/questions/643682/reading-and-writing-images-to-an-sqlite-db-for-iphone-use/643819#643819
Personally, I use this to store small (~2kb) image thumbnails
alongside equations that I provide in a preloaded data SQLite database
within my application. It makes it easy to copy across the entire
database from the Mac, where I create it, to the iPhone application,
where it's used.
______________________
Brad Larson, Ph.D.
Sunset Lake Software
http://www.sunsetlakesoftware.com