ios学习iOS基础知识总结(持续更新...)工程项目需要的功能

压缩图片和相册权限

2016-12-15  本文已影响121人  傲视苍穹
- (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{
     //有访问相册的权限
}

上一篇 下一篇

猜你喜欢

热点阅读