IOS get pictures and crop from camera or album

Source: Internet
Author: User

/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

Related Article

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.