获取图片的缩略图
- (UIImage *) thumbnailImageForImage:(UIImage *) image { CGSize origImageSize = image.size; CGRect newRect = CGRectMake(0, 0, 65, 65); //确定缩放倍数 float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height/origImageSize.height); //创建位图上下文 UIGraphicsBeginImageContext(newRect.size); //确定绘图区域 CGRect projectRect; projectRect.size.width = ratio * origImageSize.width; projectRect.size.height = ratio * origImageSize.height; projectRect.origin.x = (newRect.size.width - projectRect.size.width) * 0.5; projectRect.origin.y = (newRect.size.height - projectRect.size.height) * 0.5; //在矩形区域中绘图 [image drawInRect:projectRect]; //通过上下文得到UIImage对象 UIImage * small = UIGraphicsGetImageFromCurrentImageContext(); return small; }
参考文档:《ios编程》(第二版)P.287(第16章 创建UITableViewCell子类)