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