Create a photo album Controller
Uiimagepickercontroller *pc = [[Uiimagepickercontroller alloc] init];
Photo source
Uiimagepickercontrollersourcetypephotolibrary//Album Gallery
Uiimagepickercontrollersourcetypecamera//Camera (simulator using phase chance crash, real machine can)
Uiimagepickercontrollersourcetypesavedphotosalbum Photo Gallery
Pc.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
Whether to allow editing of pictures
pc.allowsediting = YES;
Pc.delegate = self; Set up a proxy <UINavigationControllerDelegate,UIImagePickerControllerDelegate>//album Controller to comply with two protocols
Present the album Controller.
[Self presentviewcontroller:pc animated:yes completion:nil];
Album agent can be set inside
Proxy method for #pragma mark-album Controller
Select the image to be called after completion
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info
{
NSLog (@ "%@", info); Get a dictionary
Save the edited picture, there is information in the dictionary
Self.imageView.image = info[@ "Uiimagepickercontrollereditedimage"];
Data turns into image
UIImage imagewithdata:<# (NSData *) #>
Image (. PNG) into data
Uiimagepngrepresentation (< #UIImage *image#>)
. jpg turns into data
Parameter 2. Compression factor, 0-1.0
NSData *dataoriginal = uiimagejpegrepresentation (Self.imageView.image, 1.0);
NSData *dataedited = uiimagejpegrepresentation (self.imageView.image, 0.3);
NSLog (@ "%@", Nshomedirectory ());
Save the original picture to the sandbox
[Dataoriginal writetofile:[nsstring stringwithformat:@ "%@/library/1.jpg", Nshomedirectory ()] Atomically:YES];
The edited pictures are also saved in a convenient comparison (editing will compress, the image after the compression of the external memory smaller, put the General Assembly Blur)
[dataedited writetofile:[nsstring stringwithformat:@ "%@/library/2.jpg", Nshomedirectory ()] Atomically:YES];
Return
[Picker Dismissviewcontrolleranimated:yes Completion:nil];
}
Call album how to set Trim-B