IOS照相機的啟動,圖片的讀取,儲存demo

來源:互聯網
上載者:User

標籤:io   ar   color   os   使用   sp   for   on   log   

#import

@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIImageView *imgV;
- (IBAction)openCamera:(id)sender;

- (IBAction)openPhotoLibrary:(id)sender;

- (IBAction)openSavedPhotoAlbum:(id)sender;

@end






#import "ViewController.h"

@implementation ViewController
@synthesize imgV;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren‘t in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setImgV:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)openCamera:(id)sender
{
    //UIImagePickerController 類方法,判斷源是否可用 UIImagePickerController是一個圖片挑選控制器 可以通過三種途徑挑選圖片。Camera、PhotoLibrary、SavedPhotoAlbum
    BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];//判斷照相機是否可用(是否有網路攝影機)
    if(hasCamera == YES)
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.delegate = self;
        picker.allowsEditing = YES; //是否可編輯
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你沒有網路攝影機" delegate:nil cancelButtonTitle:@"ok!" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
   
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSLog(@"%@",info);
//    {
//        UIImagePickerControllerCropRect = "NSRect: {{-1, 320}, {1937, 1937}}";
//        UIImagePickerControllerEditedImage = "";
//        UIImagePickerControllerMediaMetadata =     {
//            DPIHeight = 72;
//            DPIWidth = 72;
//            Orientation = 6;
//            "{Exif}" =         {
//                ApertureValue = "2.970853654340484";
//                BrightnessValue = "2.246098001053075";
//                ColorSpace = 1;
//                DateTimeDigitized = "2012:09:20 11:47:12";
//                DateTimeOriginal = "2012:09:20 11:47:12";
//                ExposureMode = 0;
//                ExposureProgram = 2;
//                ExposureTime = "0.06666666666666667";
//                FNumber = "2.8";
//                Flash = 24;
//                FocalLength = "3.85";
//                ISOSpeedRatings =             (
//                                               125
//                                               );
//                MeteringMode = 5;
//                PixelXDimension = 2592;
//                PixelYDimension = 1936;
//                SceneType = 1;
//                SensingMethod = 2;
//                Sharpness = 2;
//                ShutterSpeedValue = "3.911199862602335";
//                SubjectArea =             (
//                                           1295,
//                                           967,
//                                           699,
//                                           696
//                                           );
//                WhiteBalance = 0;
//            };
//            "{TIFF}" =         {
//                DateTime = "2012:09:20 11:47:12";
//                Make = Apple;
//                Model = "iPhone 4";
//                Software = "5.1.1";
//                XResolution = 72;
//                YResolution = 72;
//            };
//        };
//        UIImagePickerControllerMediaType = "public.image";
//        UIImagePickerControllerOriginalImage = "";
//    }
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imgV.image = image;
   
    //如果想把某個UIImageObject Storage Service到預設相簿,使用下面代碼
    //UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

   
    [self dismissModalViewControllerAnimated:YES];

}

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

- (IBAction)openPhotoLibrary:(id)sender //相簿清單
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.allowsEditing = YES; //是否可編輯
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (IBAction)openSavedPhotoAlbum:(id)sender //預設相簿
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    picker.delegate = self;
    picker.allowsEditing = YES; //是否可編輯
    [self presentModalViewController:picker animated:YES];
    [picker release];

}
- (void)dealloc {
    [imgV release];
    [super dealloc];
}
@end

IOS照相機的啟動,圖片的讀取,儲存demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.