- (UIImage *)resetSizeSourceImage:(UIImage*)sourceImage {
CGFloat scaleToWidth = 1280;
if ( scaleToWidth > MAX(sourceImage.size.width, sourceImage.size.height)) {
return sourceImage;
}
if (sourceImage.size.width >sourceImage.size.height ) {
CGFloat height = (scaleToWidth / sourceImage.size.width) * sourceImage.size.height;
CGRect rect = CGRectMake(0, 0, scaleToWidth, height);
UIGraphicsBeginImageContext(rect.size);
[sourceImage drawInRect:rect];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}else{
CGFloat width = (scaleToWidth / sourceImage.size.height) * sourceImage.size.width;
CGRect rect = CGRectMake(0, 0, width, scaleToWidth);
UIGraphicsBeginImageContext(rect.size);
[sourceImage drawInRect:rect];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
}
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusNotDetermined) {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"允许访问");
});
}else{
NSLog(@"拒绝访问");
}
}];
}
if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) {
//没有访问相册的权限
return ;
}else{
//有访问相册的权限
}