问题描述
我有一个相机应用程序,当我点击相机按钮时相机打开,用户可以从相机或照片库拍照。
I have a camera application in which when I click on the camera button the camera opens and user can take picture from camera or from photo-library.
我有完成了相机部件,当用户点击按钮时相机打开,他可以拍照。问题是用户从相机拍摄的图片必须保存到SQLite数据库中。我被困在这一部分。有人可以帮我保存从相机中取出的图像吗?
I have done the camera part such that when user clicks on the button the camera opens and he can take a picture. The problem is the picture the user has taken from the camera must be saved into SQLite database. I am stuck in this part. Could anybody help me on how to save image taken from camera ?
推荐答案
如果您使用的是 UIImagePickerController
,你可以在 imagePickerController中获取图片:didFinishPickingMediaWithInfo:
委托方法。你得到的图像是 UIImage
对象。
If you are using the UIImagePickerController
, you can get the image in its imagePickerController:didFinishPickingMediaWithInfo:
delegate method. The image you get is an UIImage
object.
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
现在 NSData
有一个方法 bytes
返回 void *
。这将指向一个C类型数组,它应该与SQLite一起使用。
Now NSData
has a method bytes
which returns void*
. This will point to a C type array which should play well with SQLite.
这篇关于如何在iOS上的SQLite数据库中拍照并保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!