iOS image compression upload Server ultimate Solution
Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:12px">I finally went to the program as Follows:</span></p></p><p><p></p></p><p class="p1"><p class="p1"></p></p><pre name="code" class="objc"><pre name="code" class="objc">/** * Dynamic Release image compression * * @param source_image Original image * @param maxSize Limited image size * * @return return the processed picture */-(NSDA Ta *) resetsizeofimagedata: (UIImage *) source_image maxSize: (nsinteger) maxSize;</pre></pre><br><span style="font-size:12px"><span style="font-size:12px">first adjust the resolution, the resolution can set a value on its own, greater than the reduction to this resolution, the small surplus to maintain the original Resolution. The compression ratio is then set according to the final size, such as passing in maxsize = 100k, and finally calculating the approximate compression ratio of this size. Basically finally out of the image data according to the current resolution can maintain the same size and not too vague, with, the final effect of Weibo should be similar, the code still needs to be optimized! </span></span><p><p></p></p><p class="p1"><p class="p1"></p></p><pre name="code" class="objc">-(nsdata *) resetsizeofimagedata: (UIImage *) source_image maxSize: (nsinteger) Maxsize{//first Adjust resolution cgsize newSize = Cgsiz Emake (source_image.size.width, source_image.size.height); CGFloat tempheight = newsize.height/1024; CGFloat tempwidth = newsize.width/1024; If (tempwidth > 1.0 && tempwidth > Tempheight) {newSize = Cgsizemake (SOURCE_IMAGE.SIZE.WIDTH/TEMPW idth, source_image.size.height/tempwidth); } else if (tempheight > 1.0 && tempwidth < Tempheight) {newSize = Cgsizemake (source_image.size.wid th/tempheight, source_image.size.height/tempheight); } Uigraphicsbeginimagecontext (newSize); [source_image Drawinrect:cgrectmake (0,0,newsize.width,newsize.height)]; UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); Sizing NSData *imagedata = uiimagejpegrepresentation (newimage,1.0); Nsuinteger Sizeorigin = [imageData length]; Nsuinteger sizeoriginkb = sizeorigin/1024; If (sizeoriginkb > MaxSize) {nsdata *finallimagedata = uiimagejpegrepresentation (newimage,0.50); Return finallimagedata; } return imageData;}</pre><br><br><p><p></p></p><p class="p1"><p class="p1"><br></p></p><p class="p1"><p class="p1"><br></p></p><p class="p1"><p class="p1"><br></p></p><br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>iOS image compression upload Server ultimate Solution</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service