【问题标题】:iOS Help: How to use camera to take picture and save it on iPhone?iOS 帮助:如何使用相机拍照并保存在 iPhone 上?
【发布时间】:2012-07-21 06:50:56
【问题描述】:

我是 iPhone 开发的新手。我需要制作一个应用程序,用户可以在其中拍照,然后将其保存在 iPhone 上,而且我必须使用 SQLite 数据库来存储图像并稍后显示它。

谁能帮我提供示例代码和程序说明?

编辑:我制作了一个使用 UIImageView 拍照的按钮,但我不确定它是否有效,因为我没有 iPhone:

if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = 
    UIImagePickerControllerSourceTypeCamera;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];
    imagePicker = nil;
    newMedia = YES;
}

以上代码使用前置摄像头

【问题讨论】:

  • Shahnawaz - 有很多关于这个主题的教程,还有 Apple 的 WWDC 视频,甚至 YouTube 上的视频。你有没有努力去寻找这些资源?
  • 我正在寻找有关如何存储文件路径以及如何保存图片的建议。我尝试了一些我不知道有必要展示它的东西,但我会编辑帖子并现在展示它。

标签: iphone objective-c ios ios5 ios4


【解决方案1】:

你可以使用UIImagePickerController类拍照.. 您可以使用以下方法捕获图像并存储它..

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //put code for store image
 }                

【讨论】:

  • @Janak Nirmal 我希望用户拥有最新的显示图片。是否可以只拍摄新照片并阻止选择现有选项?
【解决方案2】:

您可以使用苹果开发者库中提供的示例

查看这些示例

还有更多参考资料可供使用。

快乐编码:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 2012-05-17
    相关资源
    最近更新 更多