A picture according to the required size of the compression and amplification of the ratio, and then intercept the need for the size of the part, do not know to say clearly no, anyway that means it!
+ (UIImage *) Compressimagewith: (UIImage *) Image width: (float) Width Height: (float) height{floatImageWidth =Image.size.width; floatImageHeight =Image.size.height; floatWidthscale = imagewidth/width; floatHeightscale = imageheight/height; //Create a bitmap context//and set it to the context that is currently being usedUigraphicsbeginimagecontext (cgsizemake (width, height)); if(Widthscale >Heightscale) {[Image Drawinrect:cgrectmake (0,0, ImageWidth/Heightscale, height)]; } Else{[Image Drawinrect:cgrectmake (0,0, Width, imageheight/Widthscale)]; } //create a resized picture from the current contextUIImage *newimage =Uigraphicsgetimagefromcurrentimagecontext (); [NewImage retain]; //make the current context out of the stackUigraphicsendimagecontext (); returnNewImage; }
IOS: Equal compression code