ios - Reducing the quality of a UIImage (compressing it) -


hi trying compress uiimage code so:

    var data = uiimagejpegrepresentation(image, 1.0)     print("old image size \(data?.length) bytes")     data = uiimagejpegrepresentation(image, 0.7)     print("new image size \(data?.length) bytes")     let optimizedimage = uiimage(data: data!, scale: 1.0) 

the print out is:

old image size optional(5951798) bytes new image size optional(1416792) bytes 

later on in app upload uiimage webserver (it's converted nsdata first). when check size it's original 5951798 bytes. doing wrong here?

a uiimage provides bitmap (uncompressed) version of image can used rendering image screen. jpeg data of image can compressed reducing quality (the colour variance in effect) of image, in jpeg data. once compressed jpeg unpacked uiimage again requires full bitmap size (which based on colour format , image dimensions).

basically, keep best quality image can display , compress before upload.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -