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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -