/load user image-(void) uesrimageclicked {uiactionsheet *sheet; Determine if the camera is supported if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { sheet = [[Uiactionsheet alloc] initwithtitle:@ "Select Image" Delegate:self cancelbuttontitle:nil destructivebuttontitle:@ "Cancel" otherbuttontitles:@ "Photo", @ "select from album", Nil]; } else {sheet = [[Uiactionsheet alloc] initwithtitle:@ "Select Image" Delegate:self cancelbuttontitle:nil DESTRUCTIVEB uttontitle:@ "Cancel" otherbuttontitles:@ "Select from album", Nil]; } Sheet.tag = 255; [Sheet ShowInView:self.view]; } #pragma mark-action sheet delegte-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsintege R) Buttonindex {if (Actionsheet.tag = = 255) {Nsuinteger sourcetype = Uiimagepickercontrollersourcetypephotoli Brary; Determine if the camera is supported if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {Switch (buttonindex) {case 0:return; Case 1://Camera sourcetype = Uiimagepickercontrollersourcetypecamera; Break Case 2://album sourcetype = Uiimagepickercontrollersourcetypephotolibrary; Break }} else {if (Buttonindex = = 0) {return; } else {sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum; }}//Jump to camera or album page Uiimagepickercontroller *imagepickercontroller = [[Uiimagepickercontroller allo c] init]; Imagepickercontroller.delegate = self; imagepickercontroller.allowsediting = YES; Imagepickercontroller.sourcetype = sourcetype; [Self Presentviewcontroller:imagepickercontroller Animated:yes completion:^{}]; }} #pragma mark-image picker delegte-(void) ImagepiCkercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (nsdictionary *) info {[Picker Dismissviewcontrolleranimated:yes completion:^{}]; UIImage *image = [info uiimagepickercontrolleroriginalimage]; Userimageview.image = image; NSData *imagedata = uiimagejpegrepresentation (image, Compressed_rate); UIImage *compressedimage = [UIImage imagewithdata:imagedata]; [Httprequestmanager uploadimage:compressedimage httpClient:self.httpClient delegate:self]; }//load user image-(void) uesrimageclicked{uiactionsheet *sheet; Determine if the camera is supported if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {She ET = [[Uiactionsheet alloc] initwithtitle:@ "Select Image" Delegate:self cancelbuttontitle:nil destructivebuttontitle:@ "Cancel" otherbuttontitles:@ "Photo", @ "select from album", Nil]; } else {sheet = [[Uiactionsheet alloc] initwithtitle:@ "Select Image" Delegate:self cancelbuttontitle:nil destructivebuttontitle:@ "Cancel" otherbuttontitles:@ "Select from album", Nil]; } Sheet.tag = 255; [Sheet ShowInView:self.view];} #pragma mark-action sheet delegte-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex{if (Actionsheet.tag = = 255) {Nsuinteger sourcetype = uiimagepickercontrollersourcetypephotolibrary ; Determine if the camera is supported if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { Switch (buttonindex) {case 0:return; Case 1://Camera sourcetype = Uiimagepickercontrollersourcetypecamera; Break Case 2://album sourcetype = Uiimagepickercontrollersourcetypephotolibrary; Break }} else {if (Buttonindex = = 0) {return; } else {sourcetype = UiimagepickercontrollersourCetypesavedphotosalbum; }}//Jump to camera or album page Uiimagepickercontroller *imagepickercontroller = [[Uiimagepickercontroller alloc] I NIT]; Imagepickercontroller.delegate = self; imagepickercontroller.allowsediting = YES; Imagepickercontroller.sourcetype = sourcetype; [Self Presentviewcontroller:imagepickercontroller Animated:yes completion:^{}]; }} #pragma mark-image picker delegte-(void) Imagepickercontroller: (Uiimagepickercontroller *) picker Didfinishpickingmediawithinfo: (nsdictionary *) info{[picker Dismissviewcontrolleranimated:yes completion:^{}]; UIImage *image = [info uiimagepickercontrolleroriginalimage]; Userimageview.image = image; NSData *imagedata = uiimagejpegrepresentation (image, Compressed_rate); UIImage *compressedimage = [UIImage imagewithdata:imagedata]; [Httprequestmanager uploadimage:compressedimage httpClient:self.httpClient delegate:self]; }
The returned image is not a square and displays a noticeable stretch in the view of the user's avatar. Studied for a long time various cutting algorithms, and even want to create a view to deal with. Suddenly found in the code from the camera, album to take pictures of the
Uiimagepickercontrolleroriginalimage
So I followed it in a look:
Uikit_extern nsstring *const Uiimagepickercontrollermediatype; An nsstring (UTI, i.e. Kuttypeimage)
Uikit_extern nsstring *const uiimagepickercontrolleroriginalimage; A UIImage
Uikit_extern nsstring *const uiimagepickercontrollereditedimage; A UIImage
Uikit_extern nsstring *const Uiimagepickercontrollercroprect; An Nsvalue (CGRect)
Uikit_extern nsstring *const Uiimagepickercontrollermediaurl; An Nsurl
Uikit_extern nsstring *const uiimagepickercontrollerreferenceurl Ns_available_ios (4_1); An Nsurl-references an
Change Uiimagepickercontrolleroriginalimage to Uiimagepickercontrollereditedimage, everything is done.
IOS get pictures and crop from camera or album