【发布时间】:2013-06-05 19:09:15
【问题描述】:
您好,我想将图像发送到网络服务。但我想将用户选择的任何图像调整为 75 x 75 并将其发送到 Web 服务。如何将此图像调整为 75 x 75
谢谢
【问题讨论】:
-
stackoverflow.com/questions/10491080/… 看看这个来自 Rob 的真棒答案
您好,我想将图像发送到网络服务。但我想将用户选择的任何图像调整为 75 x 75 并将其发送到 Web 服务。如何将此图像调整为 75 x 75
谢谢
【问题讨论】:
尝试实现下面的代码。可能对你有帮助:
CGRect rect = CGRectMake(0,0,75,75);
UIGraphicsBeginImageContext( rect.size );
[yourCurrentOriginalImage drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
【讨论】:
UIImagePNGRepresentation
使用此方法调整图像大小:
+(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;
}
【讨论】: