- (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{
//有访问相册的权限
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。