Ios-camera-management

提供:Dev Guides
移動先:案内検索

iOS-カメラ管理

カメラは、モバイルデバイスの一般的な機能の1つです。 カメラで写真を撮ってアプリケーションで使用することは可能ですが、それも非常に簡単です。

カメラ管理-関与する手順

ステップ1 *-簡単な Viewベースのアプリケーション*を作成します。

ステップ2 *- *ViewController.xibbutton を追加し、ボタンのIBActionを作成します。

  • ステップ3 *-*画像ビュー*を追加し、imageOutという名前のIBOutletを作成します。

ステップ4 *-次のように *ViewController.h を更新します-

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIImagePickerControllerDelegate> {
   UIImagePickerController *imagePicker;
   IBOutlet UIImageView *imageView;
}

- (IBAction)showCamera:(id)sender;
@end

ステップ5 *-次のように *ViewController.m を更新します-

#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
   [super didReceiveMemoryWarning];
  //Dispose of any resources that can be recreated.
}

- (IBAction)showCamera:(id)sender {
   imagePicker.allowsEditing = YES;

   if ([UIImagePickerController isSourceTypeAvailable:
   UIImagePickerControllerSourceTypeCamera]) {
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
   } else {
      imagePicker.sourceType =
      UIImagePickerControllerSourceTypePhotoLibrary;
   }
   [self presentModalViewController:imagePicker animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker
   didFinishPickingMediaWithInfo:(NSDictionary *)info {
      UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

      if (image == nil) {
         image = [info objectForKey:UIImagePickerControllerOriginalImage];
      }
   imageView.image = image;
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
   [self dismissModalViewControllerAnimated:YES];
}
@end

出力

アプリケーションを実行し、カメラの表示ボタンをクリックすると、次の出力が得られます-

iOSチュートリアル

写真を撮ると、写真を編集できます。つまり、以下に示すように移動および拡大縮小できます-

iOSチュートリアル