图片保存到相册⬇️
Photos.framework 系统库
#import <Photos/Photos.h>//系统头文件
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
UIImage * images = [UIImage imageWithContentsOfFile:@""];
PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromImage:images];
}completionHandler:^(BOOL success, NSError * _Nullable error) {
保存失败回调
}];
图片压缩⬇️
UIImage *img = [UIImage imageWithContentsOfFile:imageName];
UIGraphicsBeginImageContext(CGSizeMake(width, height));
[img drawInRect:CGRectMake(0, 0, width, height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgDataJpg = UIImageJPEGRepresentation(scaledImage,0.01);
NSString *base64 = [imgDataJpg base64Encoding];//这根据需求来可以不用转base64字符串