iOS development - URL get the picture size (width and height) according to the picture
https://www.jianshu.com/p/854dc9c810c9
The first method is essentially lossless compression (the naked eye can not see the basic difference, I do not know what in the end lost)
UIImageJPEGRepresentation (Image, compression)
1
This method can be iPhone6 photographs compressed to a few hundred Kb limit, after compression to the limit no matter how small this parameter, the function returns the size of the data will no longer change. That compression of this method is the minimum value. The resulting format is jpg. In addition there is a greater method UIImagePNGRepresentation (<# UIImage * _Nonnull image #>) data obtained by this method will be the method of data than the previous space.
The second method is basically reset the image pixel size to achieve the purpose of compression
in order to achieve the purpose of compression, this method is lossy, that will reduce the picture quality.
The following is a method of compressing
// Compress Pictures (redraw the picture)
- (UIImage *) imageWithImageSimple: (UIImage *) image scaledToSize: (CGSize) newSize
{
// first set up the new image size according to the image size and aspect ratio newSize (for no deformation reaches scaling purposes)
CGFloat wtmp;
CGFloat HTMP;
CGSize ImgSize = image.size;
IF (imgSize.width> imgSize.height) {
wtmp = newSize.width;
HTMP * = imgSize.height wtmp / imgSize.width ;
} the else {
HTMP = newSize.height;
wtmp * = imgSize.width HTMP / imgSize.height;
}
// Create a graphics image context
UIGraphicsBeginImageContext(CGSizeMake(wTmp, hTmp));
// Tell the old image to draw in this new context, with the desired
// new size
[image drawInRect:CGRectMake(0,0,wTmp,hTmp)];
// Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// End the context
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}