Image compression before uploading a picture:
NSData *imagedata = uiimagejpegrepresentation (Self.uploadimage, 0.75);
Image by 0.75 mass compression-"converted to NSData
NSString *file_name = [Timeutil getdatestringwithformat:@ "Yyyy-mm-dd-hh-mm-ss"];
Take the time for the picture name
NSString *upload_name =[nsstring stringwithformat:@ "%@.jpg", file_name];
The name of the uploaded image
[Request Setdata:imagedata withfilename:upload_nameandcontenttype:@ "Image/jpeg" forkey:@ "Upload_file"];
The UIImageJPEGRepresentation function requires two parameters: a reference to the picture and a compression factor.
Uiimagepngrepresentation only requires a picture reference as a parameter.
Comparison found:
Uiimagepngrepresentation (uiimage* image) is much larger than the amount of image data returned by uiimagejpegrepresentation (uiimage* image, 1.0).
For example, a photo that reads the same view as the camera
Uiimagepngrepresentation () The amount of data returned is 199K
The amount of data returned by UIImageJPEGRepresentation (uiimage* image, 1.0) is only 140KB
More than 50 KB less than the former.
If the clarity of the picture is not required, you can also significantly reduce the amount of image data by setting the second parameter of the UIImageJPEGRepresentation function.
For example, a picture just taken, when reading data by calling UIImageJPEGRepresentation (uiimage* image, 1.0), returns the data size 140KB
However, after changing the compression factor, when reading data by calling UIImageJPEGRepresentation (uiimage* image, 0.5), the returned data size is only more than 11KB, which greatly compresses the amount of data in the image.
And from a perspective point of view, the quality of the picture is not significantly reduced. Therefore, when reading the image data content, it is recommended to use uiimagejpegrepresentation, and according to their actual use of the scene, set the compression coefficient, further reduce the size of the image data.
IOS image Compression