开发者

How to store images in the sqlite database in iphone [duplicate]

This q开发者_如何学Pythonuestion already has answers here: Closed 11 years ago.

Possible Duplicate:

Reading and writing images to an SQLite DB for iPhone use

How to store a images file in database in blob type in sqlite database and how to retrieve a image from the database.


save image in your nsdocument directory. in database save the path of this image. this is a good approach. if u save blob in data base database will so heavy. it take time to load.


First convert image into NSData
Then NSData into bytes
Then store that bytes... Sorry I don't know the method that should be called, because I use core data which is far better than sqlite c api


The easiest way is to use an Objective-C sqlite wrapper such as fmdb. Then you can pass an NSData handle from UIImagePNGRepresentation() into the wrapper as a blob.

Alternatively, you could do something like this:

NSData *rawImage = UIImagePNGRepresentation(myUIImage);
sqlite3_bind_blob(mySavedSQLStatement, 2, [rawImage bytes], [rawImage length], SQLITE_TRANSIENT);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜