如何从iphone的本机应用程序打开相机?

时间:2023-01-25 07:38:02

I want to write a app in which I open the camera take a picture and then edit the picture.I want to apply some cool effects on image as well.something like image editing...does some one knows a good or I say best approach to achieve this?

我想写一个app,打开相机拍照,然后编辑照片。我也想在图像上应用一些很酷的效果。类似的图像编辑……有人知道一个好方法吗?

I want to know that is open-gl necessary to create an aap like image editing ?

我想知道,要创建一个像图像编辑这样的aap, open-gl有必要吗?

2 个解决方案

#1


4  

This is truly easy. Your code will be in a subclass of UIViewController, let this class conform to the UIImagePickerControllerDelegate protocol, this allows your controller to receive images from the camera and/or users library.

这确实是容易。您的代码将在UIViewController的子类中,让这个类符合UIImagePickerControllerDelegate协议,这允许您的控制器接收来自相机和/或用户库的图像。

Now you have to create and display a UIImagePickerController, this view controller can be used for both selecting images from the users library, and taking images/video with the camera. Implement something like this:

现在你必须创建并显示一个UIImagePickerController,这个视图控制器可以用于从用户库中选择图像,以及用相机拍摄图像/视频。实现这样的:

-(IBAction)takePictureWithCamera {
  UIImagePickerController* controller = [[UIImagePickerController alloc] init];
  controller.delegate = self;
  [self presentModalViewController:controller animated:YES];
  [controller release];
}

This will display the image picker, see documentation for UIImagePickerController for how to customize further if needed.

这将显示image picker,查看UIImagePickerController的文档,以了解如何在需要时进一步定制。

Next you need to receive the image the user picks, or takes with the camera. This is done by implementing the method imagePickerController:didFinishPickingMediaWithInfo: from the UIImagePickerControllerDelegate protocol.

接下来,您需要接收用户选择的图像,或者使用相机拍摄。这是通过实现方法imagePickerController:didFinishPickingMediaWithInfo:从UIImagePickerControllerDelegate协议实现的。

-(void)imagePickerController:(UIImagePickerController*)picker
    didFinishPickingMediaWithInfo:(NSDictionary*)info {
  UIImage* image = [info objectForKey: UIImagePickerControllerOriginalImage];
  // Do stuff to image.
}

And that is it.

这就是它。

#2


2  

Take a look at the UIImagePickerController class. It's a view controller that you can present modally, and it lets you "pick" an image from the camera using the iPhone's native interface for taking photos.

看看UIImagePickerController类。它是一个视图控制器,你可以用modally显示,它可以让你用iPhone的本机界面从相机中“选择”一张照片。

#1


4  

This is truly easy. Your code will be in a subclass of UIViewController, let this class conform to the UIImagePickerControllerDelegate protocol, this allows your controller to receive images from the camera and/or users library.

这确实是容易。您的代码将在UIViewController的子类中,让这个类符合UIImagePickerControllerDelegate协议,这允许您的控制器接收来自相机和/或用户库的图像。

Now you have to create and display a UIImagePickerController, this view controller can be used for both selecting images from the users library, and taking images/video with the camera. Implement something like this:

现在你必须创建并显示一个UIImagePickerController,这个视图控制器可以用于从用户库中选择图像,以及用相机拍摄图像/视频。实现这样的:

-(IBAction)takePictureWithCamera {
  UIImagePickerController* controller = [[UIImagePickerController alloc] init];
  controller.delegate = self;
  [self presentModalViewController:controller animated:YES];
  [controller release];
}

This will display the image picker, see documentation for UIImagePickerController for how to customize further if needed.

这将显示image picker,查看UIImagePickerController的文档,以了解如何在需要时进一步定制。

Next you need to receive the image the user picks, or takes with the camera. This is done by implementing the method imagePickerController:didFinishPickingMediaWithInfo: from the UIImagePickerControllerDelegate protocol.

接下来,您需要接收用户选择的图像,或者使用相机拍摄。这是通过实现方法imagePickerController:didFinishPickingMediaWithInfo:从UIImagePickerControllerDelegate协议实现的。

-(void)imagePickerController:(UIImagePickerController*)picker
    didFinishPickingMediaWithInfo:(NSDictionary*)info {
  UIImage* image = [info objectForKey: UIImagePickerControllerOriginalImage];
  // Do stuff to image.
}

And that is it.

这就是它。

#2


2  

Take a look at the UIImagePickerController class. It's a view controller that you can present modally, and it lets you "pick" an image from the camera using the iPhone's native interface for taking photos.

看看UIImagePickerController类。它是一个视图控制器,你可以用modally显示,它可以让你用iPhone的本机界面从相机中“选择”一张照片。