ios – Discover picture measurement and optimise in Swift

In my utility, I am utilizing YPImagepicker for choosing photographs from library and digicam. I wish to know picture measurement in MB after choosing the photographs or capturing a photograph. Process is to transform the photographs into information and ship to backend through REST API. As of now we’re limiting photographs into 5. So I wish to see the scale of each photographs whether it is greater than 1 Mb must compress into 1mb.

let imgData = NSData(information: picture.jpegData(compressionQuality: 1)!)
var imageSize: Int = imgData.depend
print("precise measurement of picture in KB: %f ", Double(imageSize) / 1024.0 / 1024.0)

the above pattern I’ve used to examine the scale of the picture however I am not seeing the right file measurement. For eg, I am capturing one photograph by way of app and it’s getting saved in album after I examine the picture measurement it reveals 3.4 MB in photograph element however in code I am not getting the identical measurement. What’s finest approach to obtain this?

See also  ios - Flutter: override the non-public state implementation of a Cupertino widget?

Leave a Reply