我想把图像的大小调整为正方形。如果原始图像不是正方形的,我想添加透明背景,使图像的纵横比保持不变。我的代码如下,我知道我现在没有做任何添加透明背景。有办法吗
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;
}];