我想将图像调整为正方形。如果原始图像不是正方形,我想为该图像的长宽比添加透明背景。我的代码如下,我知道我现在不做任何事情来添加透明背景。 requestImageForAsset
是否可以通过默认方式执行类似的操作?
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = true;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
PHImageManager *manager = [PHImageManager defaultManager];
[manager requestImageForAsset:_asset
targetSize:!_isLogo? LARGE_IMAGE_SIZE : COMPANY_LOGO_LARGE_SIZE
contentMode:PHImageContentModeAspectFit
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info) {
NSData *imageData = UIImagePNGRepresentation(image);
NSString *filename = [NSString stringWithFormat:@"/img_%f.png", [[Utils getCurrentDate] timeIntervalSince1970]];
NSString *tempPath = [documentsDirectory stringByAppendingString:filename];
[imageData writeToFile:tempPath atomically:YES];
largeImage = image;
}];