如何减小UIIMageview上图像显示的大小

| 我是iPhone开发的新手 我的问题是,在我的应用中,我有
UIImageview
button1
button2
button1
用于访问保存的照片库中的图像,而button2用于将图像存储在数据库中, 但是图像尺寸为(800x800),非常大,我想以(50x50)尺寸存储 单击button2时如何缩小图像尺寸?     
已邀请:
// grab the original image
UIImage *originalImage = [UIImage imageNamed:@\"myImage.png\"];

UIImage *scaledImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:50/800 orientation:UIImageOrientationUp];
    
此类别将为您完成工作- UIImage + Additions.h-
@interface UIImage (UIImageAdditions)
- (UIImage*)scaleToSize:(CGSize)size;
@end
UIImage + Additions.m-
@implementation UIImage (UIImageAdditions)

- (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
    
+ (UIImage*)imageWithImage:(UIImage*)image 
               scaledToSize:(CGSize)newSize;
{
   UIGraphicsBeginImageContext( newSize );
   [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
   UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   return newImage;
}
请参阅先前的SO问题,用iPhone SDK调整大小/优化图像大小的最简单方法是什么?供进一步参考     

要回复问题请先登录注册