我已尝试使用图片大小调整插件来压缩我的应用中的图片。但它降低了清晰度并且看起来不太好。任何人都可以告诉我在我的iPhone应用程序中动态压缩图像的任何其他解决方案。
#import <Foundation/Foundation.h>
@interface UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size;
@end
#import "UIImage+Resize.h"
// Put this in UIImageResizing.m
@implementation UIImage (Resize)
- (UIImage*)scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@end