awkward/Tatsi

Low Quality Images after Importing!

Closed this issue · 4 comments

When I select a photo from library through Tatsi, the photo will be low quality! How can I fix it?

Thanks for Answering

Can you show me the code in which you turn the PHAsset into an image?

Sure! Is it a problem of PHAssets?
Screenshot 2020-06-09 at 10 42 03

Well, the problem of the quality is in the PH(Caching)ImageManager. Tatsi doesn't do anything with the resolution or quality.

There are a number of problems with the code you've just shared:

  • The PHCachingImageManager is useless in this case because you are always creating a new instance (see line 48). I would recommend using either PHImageManager.default or creating your own shared instance of PHCachingImageManager
  • requestImage is an asynchronous operation, this means it isn't guaranteed that thumbnail is filled before you return from the code. You can make it synchronous, but you should check the docs for that.
  • And here is your actual problem, requestImage will first give you a lower quality image and will then call the callback again to give you a higher quality. However, because you return, it will never get the second call to the callback.

The discussion on this page of the docs will help you out: https://developer.apple.com/documentation/photokit/phimagemanager/1616964-requestimage

Also on a side note: targetSize is the size in pixels I believe. This contradicts the coordinate system of iOS, the coordinate space of iOS is in points (on newer iPhones 1 point = 2 or 3 pixels).

This means that on a modern iPhone the image that gets created is 100x100 pixels and not 100x100 points. Displaying it in a UIImageView of 100x100 points will make it look like an image of 50x50 pixels that is upscaled.

You helped me a lot!

Thank you so much!