Access album camera image head in iOS development
SOURCE http://download.csdn.net/download/jingjingxujiayou/7270479
In the APPDELEGATE.M file
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{ Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; Override point for customization after application launch. Self.window.backgroundColor = [Uicolor whitecolor]; [Self.window makekeyandvisible]; Self.window.rootViewController = [[Dateviewcontroller alloc]init]; return YES;}
DateViewController.h
#import <UIKit/UIKit.h> @interface Dateviewcontroller:uiviewcontroller<uiimagepickercontrollerdelegate, Uinavigationbardelegate> @property (nonatomic,retain) uiimageview* imageview1; @property (Nonatomic,retain) uiimagepickercontroller* Imagepicker; @end
Dateviewcontroller.m
dateviewcontroller.m//datepick////Created by 5_2 on 14-4-29.//Copyright (c) 2014 frountion. All rights reserved.//#import "DateViewController.h" @interface Dateviewcontroller () @end @implementation Dateviewcontroller@synthesize imageview1,imagepicker;-(ID) initwithnibname: (NSString *) NibNameOrNil Bundle: ( NSBundle *) nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super viewdidload];//do any additional setup after loading the view. ----------1 Load pictures from the network Imageview1 = [[Uiimageview alloc]initwithframe:cgrectmake (10, 50, 300, 200)]; Imageview1.backgroundcolor = [Uicolor Yellowcolor]; [Self.view Addsubview:imageview1]; nsurl* URL = [[Nsurl alloc]initwithstring:@ "Https://www.google.com.hk/images/srpr/logo11w.png"]; nsdata* data = [NSData Datawithcontentsofurl:url]; Turn data into image uiimage* image = [UIImage Imagewithdata:data]; Show picture imageview1.image = Image; Convert the image to data nsdata* ImageData = uiimagejpegrepresentation (image, 1); NSLog (@ "%d", imagedata.length); Saved to the album, this can be in the simulator in the album Production view. Uiimagewritetosavedphotosalbum (image, Self, @selector (image:didFinishSavingWithError:contextInfo:), NULL); Access to---------2 albums UIButton *buttonphoto = [UIButton buttonwithtype:uibuttontyperoundedrect]; Buttonphoto.tag = 100; Buttonphoto.frame = CGRectMake (50, 250, 80, 50); [Buttonphoto settitle:@ "Access album" Forstate:uicontrolstatenormal]; [Buttonphoto addtarget:self Action: @selector (look:) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:buttonphoto]; Access to the---------3 camera UIButton *buttoncamera = [UIButton buttonwithtype:uibuttontyperoundedrect]; Buttoncamera.tag = 200; Buttoncamera.frame = CGRectMake (50, 310, 80, 50); [Buttoncamera settitle:@ "Access Camera" forstate:uicontrolstatenormal]; [Buttoncamera addtarget:self Action: @selector (look:) FOrcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:buttoncamera]; }/*-(void) Look: (uibutton*) button{uiimagepickercontroller* imagepicker = [[Uiimagepickercontroller alloc]init]; Imagepicker.delegate = self; Type of Access album type//uiimagepickercontrollersourcetypephotolibrary,//uiimagepickercontrollersourcetypecamera, = = = Access Camera//uiimagepickercontrollersourcetypesavedphotosalbum ======= can only access pictures of the first column Imagepicker.sourcetype = UII Magepickercontrollersourcetypephotolibrary; Display the [Self Presentviewcontroller:imagepicker Animated:yes completion:^{}] in a friction animation mode; if (Button.tag = =) {//uiimagepickercontrollercameradevicefront = = = Front Camera//uiimagepickercontrollercamera Devicerear = = = After camera BOOL iscamrma = [Uiimagepickercontroller Iscameradeviceavailable:uiimagepickercontrollercamerad Evicerear]; if (!iscamrma) {NSLog (@ "no camera"); Return }//Webcam imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera; Allow editing of imagepicker.allowsediting =yes; }}*/-(void) Look: (uibutton*) button{if (Button.tag = =) {Imagepicker = [[Uiimagepickercontroller alloc]init]; Imagepicker.delegate = self; Type of Access album type//uiimagepickercontrollersourcetypephotolibrary,//uiimagepickercontrollersourcetypecamera, = = = Access Camera//uiimagepickercontrollersourcetypesavedphotosalbum ======= can only access pictures of the first column Imagepicker.sourcetype = UII Magepickercontrollersourcetypephotolibrary; Display the [Self Presentviewcontroller:imagepicker Animated:yes completion:^{}] in a friction animation mode; }else {//Note camera access needs to be//uiimagepickercontrollercameradevicefront on the real machine = = = Front Camera//uiim Agepickercontrollercameradevicerear = = = After camera BOOL iscamrma = [Uiimagepickercontroller Iscameradeviceavailable:uiima Gepickercontrollercameradevicerear]; if (!iscamrma) {NSLog (@ "no camera"); Return }//Webcam imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera; Allow editing of imagepicker.allowsediting =yes; }}//---------2 album access #pragma mark-uiimagepickercontrollerdelegate//album is selected after call-(void) Imagepickercontroller: ( Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (nsdictionary *) info{// Uiimagepickercontrolleroriginalimage = = To take the original picture//uiimagepickercontrollereditedimage = = = Go To edit later picture uiimage* image = [i NFO Objectforkey:uiimagepickercontrollereditedimage]; Imageview1.image = image; NSLog (@ "info =%@", info); [Picker Dismissviewcontrolleranimated:yes completion:nil];} Cancel button's Click event-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{[picker Dismissviewcontrolleranimated:yes completion:null];} Save picture-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) contextinfo{ NSLog (@ "error =%@", erROR);} -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Access album camera image head in iOS development