IOS pick up the iphone local album and turn on the camera

Source: Internet
Author: User

Transfer local images to other pages in the method

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info ; , info is a dictionary value that contains the URL value of the picture you selected, which can be passed through the URL value, with the following specific code:

. h file

#import <UIKit/UIKit.h>



Sign an agreement
@interface Viewcontroller:uiviewcontroller<uinavigationcontrollerdelegate,uiimagepickercontrollerdelegate >

@end




. m file


#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Uiimageview *imageview = [[Uiimageview alloc] init];

Imageview.frame = CGRectMake (80, 50, 200, 120);

Imageview.backgroundcolor = [Uicolor Greencolor];

Imageview.tag = 1001;

[Self.view Addsubview:imageview];



UIButton *button = [UIButton buttonwithtype:uibuttontyperoundedrect];

Button.frame = CGRectMake (0, 200, 100, 30);

[Button settitle:@ "open album" Forstate:uicontrolstatenormal];

[Button addtarget:self action: @selector (Openpics) forcontrolevents:uicontroleventtouchupinside];

[Self.view Addsubview:button];



UIButton *button2 = [UIButton buttonwithtype:uibuttontyperoundedrect];

Button2.frame = CGRectMake (0, 300, 100, 30);

[Button2 settitle:@ "open Camera" forstate:uicontrolstatenormal];

[Button2 addtarget:self Action: @selector (Opencamera) forcontrolevents:uicontroleventtouchupinside];

[Self.view Addsubview:button2];

}



Turn on the camera

-(void) Opencamera {

Uiimagepickercontrollercameradevicerear Rear-facing camera

Uiimagepickercontrollercameradevicefront front-facing camera

BOOL Iscamera = [Uiimagepickercontroller iscameradeviceavailable:uiimagepickercontrollercameradevicerear];

if (!iscamera) {

NSLog (@ "no camera");

return;

}

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];

Imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera;

Imagepicker.delegate = self;

Edit mode

imagepicker.allowsediting = YES;

[Self presentviewcontroller:imagepicker animated:yes completion:^{

}];

}

Open album

-(void) Openpics {

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];

Imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;

Imagepicker.delegate = self;

Imagepicker.allowsediting =yes;

[Self presentviewcontroller:imagepicker animated:yes completion:^{

}];

}

Select a photo



-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info {

NSLog (@ "%@", info);

Uiimageview *imageview = (Uiimageview *) [Self.view viewwithtag:1001];

Uiimagepickercontrolleroriginalimage Original image

Uiimagepickercontrollereditedimage Post-editing pictures

UIImage *image = [info objectforkey:uiimagepickercontrollereditedimage];

Imageview.image = image;

[Picker Dismissviewcontrolleranimated:yes completion:null];



}

Cancel Album

-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) Picker {

[Picker Dismissviewcontrolleranimated:yes completion:null];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}



@end

This article is from the iOS blog, so be sure to keep this source http://10136044.blog.51cto.com/10126044/1679368

IOS pick up the iphone local album and turn on the camera

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.