任何代码/库来缩小UIImage? [英] Any code/library to scale down an UIImage?

查看:78
本文介绍了任何代码/库来缩小UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以帮助我缩小图像的代码或库?如果您使用iPhone拍摄照片,则其像2000x1000像素,这不是非常网络友好的。我想把它缩小到480x320。任何提示?

Is there any code or library out there that can help me scale down an image? If you take a picture with the iPhone, it is something like 2000x1000 pixels which is not very network friendly. I want to scale it down to say 480x320. Any hints?

推荐答案

这就是我正在使用的。效果很好。我一定会看这个问题,看看有没有人有更好/更快的事情。我只是将以下内容添加到 UIimage 类别上。

This is what I am using. Works well. I'll definitely be watching this question to see if anyone has anything better/faster. I just added the below to a category on UIimage.

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

  return newImage;
}

这篇关于任何代码/库来缩小UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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