读取和写入图像到SQLite DB的iPhone使用 [英] Reading and writing images to an SQLite DB for iPhone use
问题描述
我设置了一个SQLite DB,目前正在读取和写入 NSString
。我也想在数据库中存储一个图像,以后再调用它。我已经读了一些使用 NSData
和编码的图像,但我不完全确定什么语法是我想做的。任何代码片段或示例将非常感谢。
I've set up a SQLite DB that currently reads and writes NSString
s perfectly. I also want to store an image in the database and recall it later. I've read up a bit on using NSData
and encoding the image, but I'm not entirely sure what the syntax is for what I want to do. Any code snippets or examples would be greatly appreciated.
我的当前进程如下:
UIImagePickerController
- >用户从照片中选择图片 - > chosenImage设置为 UIImageView
- > 的实例现在我要拍摄此图片并将其存储在DB中
My current process goes like this:
UIImagePickerController
-> User Chooses Image from Photos -> chosenImage is set to instance of UIImageView
-> Now I want to take this image and store it in the DB
我应该提到这个调用最终会被替换为对远程服务器的调用。
I should mention this call will eventually be replaced with a call to a remote server. Not sure if this makes a difference as far as performance goes.
推荐答案
一个选项(通常在SQL中工作时更可取)将图像写入系统上的文件,并将路径(或某种其他类型的标识符)存储在数据库中。
One option (and generally preferred when working in SQL) is to write the image to a file on the system and store the path (or some other kind of identifier) in the database.
这篇关于读取和写入图像到SQLite DB的iPhone使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!