为 iPhone 使用 SQLite 数据库读取和写入图像 [英] Reading and writing images to an SQLite DB for iPhone use

查看:32
本文介绍了为 iPhone 使用 SQLite 数据库读取和写入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个 SQLite 数据库,它当前可以完美地读取和写入 NSString.我还想在数据库中存储一个图像,稍后再调用.我已经阅读了一些关于使用 NSData 和编码图像的内容,但我不完全确定我想要做什么的语法是什么.任何代码片段或示例将不胜感激.

I've set up a SQLite DB that currently reads and writes NSStrings 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 -> 用户从照片中选择图像 -> selectedImage 设置为 UIImageView 的实例 -> 现在我想拍摄这个图像并将其存储在数据库中

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.

这篇关于为 iPhone 使用 SQLite 数据库读取和写入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆