Inquiry Regarding File Size Differences When Migrating from ALAssetsLibrary to PHPhotoLibrary

We are currently in the process of migrating our application from using ALAssetsLibrary to PHPhotoLibrary to ensure compatibility with the latest versions of iOS. However, we have noticed a discrepancy in the file sizes of images obtained using PHPhotoLibrary compared to those obtained using ALAssetsLibrary.

Specifically, we would like to understand the following points:

1.Reason for File Size Differences:

What are the reasons for the difference in file sizes between images obtained using ALAssetsLibrary and those obtained using PHPhotoLibrary? Could you provide detailed information on the settings and options in PHPhotoLibrary that affect the size and quality of the images?

2.Optimal Settings:

What are the optimal settings in PHPhotoLibrary to obtain images with the same quality and file size as those obtained using ALAssetsLibrary? If possible, could you provide code examples or recommended option settings?

Have you taken a look at the documentation of PHImageManger https://developer.apple.com/documentation/photokit/loading_and_caching_assets_and_thumbnails or the information included in there header files for the relevant APIs? There are different options for different use cases so it's difficult to recommend any configurations without knowing more about exactly what ALAssetsLibrary APIs you are calling and what your use cases are.

Thank you for your response. Specifically, I replaced it as follows, but the size of tmp has approximately doubled. Since the images are for business use, I would like to import the images without changing the aspect ratio. How should I implement this?

code before replacement

ALAsset *asset = [self.assets objectAtIndex:cellDto.index];

ALAssetRepresentation *representation = [asset defaultRepresentation]; UIImage *orgImage = [UIImage imageWithCGImage:[representation fullScreenImage] scale:[representation scale] orientation:[representation orientation]];

NSData *tmp = [[NSData alloc] initWithData:UIImagePNGRepresentation( orgImage )] ;

code after replacement

PHAsset *asset = [self.assets objectAtIndex:cellDto.index]; PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = YES; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { UIImage *orgImage = result; NSData *tmp = [[NSData alloc] initWithData:UIImagePNGRepresentation(orgImage)]; }];

Your AL code was doing a resize to the current device's dimensions via [representation fullScreenImage]. This would be scaling down images giving you a smaller final image.

If you want a similar result with PhotoKit then you should provide an appropriate targetSize other than PHImageManagerMaximumSize and you can maintain aspect ratio with PHImageContentModeAspectFit.

Inquiry Regarding File Size Differences When Migrating from ALAssetsLibrary to PHPhotoLibrary
 
 
Q