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
{
float imagewidth = image.size.width;
float imageheight = image.size.height;
float Widthscale = imagewidth/width;
float Heightscale = imageheight/height;
Create a bitmap context
and set it to the context that is currently being used
Uigraphicsbeginimagecontext (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 context
UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext ();
[NewImage retain];
Make the current context out of the stack
Uigraphicsendimagecontext ();
return newimage;
}
iOS medium ratio compression code