In fact, the UIImage.length function here does not return the wrong value, it is simply the result of a lossy conversion / return from UIImage to NSData.
Setting the compression ratio to the lowest possible compression 1.0 in the UIImageJpegRepresentation will not return the original image. Although image metadata is devoid of this process, a function can and usually produces an object larger than the original. Please note that this increase in file size DOES NOT increase image quality from a compressed original. Jpegs are highly compressed for starters, so they are used so often, and the function unpacks it and then recompresses it. Its appearance, like getting Botox after age, has stretched your body, it may look like the original, but the insides are just not as good as before.
You can use a lower compression ratio for larger files close to 1.0, as the quality will decrease rapidly. In addition, depending on the final purpose of your images, the only option is to resize the image or its resolution, perhaps in addition to adjusting the compression ratio. This change will exponentially reduce data usage. Usually the use of the Internet and mobile devices does not require permission, as are images intended for digital printing. A.
You can write code that adjusts each image and presentation of NSData only as much as necessary to fit its individual data constraint.
source share