调整图像大小Objective-C [英] Resizing Images Objective-C

查看:106
本文介绍了调整图像大小Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iPhone 4及更高版本拍摄的Objective-C缩小图像,以便尽快将其发送到服务器。目前,全尺寸的图像需要很长时间。

I'm trying to downscale an image in Objective-C taken with the iPhone 4 and above so I can send it to the server as quickly as possible. At the moment the image at full size is taking ages.

我正在尝试缩小规模的当前时间是:

The current of downsizing I am trying is:

CGSize imageSize;

imageSize = CGSizeMake(484, 888);

UIImage *img = [UIImage imageWithContentsOfFile:path];

UIGraphicsBeginImageContext( imageSize );
[img drawInRect:CGRectMake(0,0,imageSize.width,imageSize.height)];
UIImage* realfrontImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *frontImageData = UIImageJPEGRepresentation(realfrontImage, 1.0);

这给我一张320x460的图像如何获得我想要的尺寸484x888。

This gives me an image of 320x460 how do I get it the size I wanted 484x888.

我们非常感谢任何帮助。

Any help would be much appreciated.

推荐答案

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

使用此方法缩小图像。

use this method to scale down your images.

这篇关于调整图像大小Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆