如何调整iOS中的图像?

嗨,我想发送图像到Web服务。 但我想调整用户select的任何图像到75×75并发送到Web服务。 我怎样才能将这个图像的大小调整为75 x 75

谢谢

尝试执行下面的代码。 这可能对您有所帮助:

CGRect rect = CGRectMake(0,0,75,75); UIGraphicsBeginImageContext( rect.size ); [yourCurrentOriginalImage drawInRect:rect]; UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *imageData = UIImagePNGRepresentation(picture1); UIImage *img=[UIImage imageWithData:imageData]; 

使用此方法调整图像大小:

 +(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)newSize { CGFloat scale = [[UIScreen mainScreen]scale]; /*You can remove the below comment if you dont want to scale the image in retina device .Dont forget to comment UIGraphicsBeginImageContextWithOptions*/ //UIGraphicsBeginImageContext(newSize); UIGraphicsBeginImageContextWithOptions(newSize, NO, scale); [img drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } 

试试这个代码:

 - (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { UIGraphicsBeginImageContext(newSize); [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }