IOS常用第三方框架 --- UIImage+Resize 调整图片大小

GitHub:https://github.com/coryalder/UIImage_Resize

提供多种方法为图片设置透明度、圆角、裁剪、调整大小等:

- (UIImage *)imageWithAlpha;- (UIImage *)transparentBorderImage:(NSUInteger)borderSize;
- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize;
- (UIImage *)croppedImage:(CGRect)bounds;
- (UIImage *)thumbnailImage:(NSInteger)thumbnailSize transparentBorder:(NSUInteger)borderSize               cornerRadius:(NSUInteger)cornerRadius       interpolationQuality:(CGInterpolationQuality)quality;- (UIImage *)resizedImage:(CGSize)newSize     interpolationQuality:(CGInterpolationQuality)quality;- (UIImage *)  resizedImageWithContentMode:(UIViewContentMode)contentMode                       bounds:(CGSize)bounds         interpolationQuality:(CGInterpolationQuality)quality;


更详细使用见:http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

ImageCacheResize 异步加载图片、缓存及调整大小

GitHub:https://github.com/toptierlabs/ImageCacheResize

整合了SDWebImage和UIImage+Resize的功能,用于图片的异步加载、缓存、以及下载完成后调整大小并显示在UIImageView上。


提供了以下API用于加载图片以及加载完成后调整图片大小:

- (void)setImageWithURL:(NSURL *)url andCropToBounds:(CGRect)bounds;
- (void)setImageWithURL:(NSURL *)url andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder andCropToBounds:(CGRect)bounds;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andResize:(CGSize)size;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options  andCropToBounds:(CGRect)bounds;


使用方法和SDWebImage一样简单,如以下官方例子:

// 按比例缩放
[imageview setImageWithURL:[NSURL URLWithString:@"http://t0.gstatic.com/images?q=tbn:ANd9GcQfraHpiabjEY8iDdBe9OUQYHMtwfuAv9ZRR0RYKuoVF_EpE8Fp5A"] andResize:CGSizeMake(30, 30) withContentMode:UIViewContentModeScaleAspectFit]; 

// 裁剪成100x100大小
[imageview setImageWithURL:[NSURL URLWithString:@"http://t0.gstatic.com/images?q=tbn:ANd9GcQfraHpiabjEY8iDdBe9OUQYHMtwfuAv9ZRR0RYKuoVF_EpE8Fp5A"] andCropToBounds:CGRectMake(0, 0, 100, 100)]; 


使用 MJPhotoBrowser 框架实现图片浏览器的步骤如下: 1. 首先需要使用 CocoaPods 将 MJPhotoBrowser 框架导入到项目中。 2. 导入框架头文件:#import "MJPhotoBrowser.h" 3. 在需要显示图片浏览器的地方,创建一个数组用来存放图片的 URL 或 UIImage 对象。 4. 遍历图片数组,将每张图片转换成 MJPhoto 对象,并将其添加到 MJPhotoBrowser 控制器的 photoArray 属性中。 5. 创建 MJPhotoBrowser 控制器对象,并设置其 currentPhotoIndex 属性为当前图片的下标。 6. 调用 presentViewController:animated:completion: 方法,将 MJPhotoBrowser 控制器推出来展示图片浏览器。 以下是示例代码: ```objc // 创建图片数组 NSMutableArray *photos = [NSMutableArray array]; for (int i = 0; i < self.imageArray.count; i++) { // 创建 MJPhoto 对象 MJPhoto *photo = [[MJPhoto alloc] init]; // 设置图片的 URL 或 UIImage 对象 photo.url = [NSURL URLWithString:self.imageArray[i]]; // 设置图片所对应的原始 UIImageView photo.srcImageView = self.imageViewArray[i]; // 添加到图片数组中 [photos addObject:photo]; } // 创建 MJPhotoBrowser 控制器对象 MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init]; // 设置图片数组 browser.photos = photos; // 设置当前显示的图片下标 browser.currentPhotoIndex = index; // 显示图片浏览器 [self presentViewController:browser animated:YES completion:nil]; ``` 其中,self.imageArray 和 self.imageViewArray 分别为存放图片 URL 或 UIImageView 对象的数组,index 为当前需要显示的图片下标。在上述代码中,我们将图片 URL 和对应的 UIImageView 对象一起存放到 MJPhoto 对象中,这样在图片浏览器中浏览时,就可以自动放大到对应的 UIImageView 的位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值