1. 图片缩放:

- (UIImage*)resizeImage:(UIImage*)image toWidth:(NSInteger)width height:(NSInteger)height
{
    
// Create a graphics context with the target size
    
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
    
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
    CGSize size = CGSizeMake(width, height);
    
if (NULL != UIGraphicsBeginImageContextWithOptions)
        UIGraphicsBeginImageContextWithOptions(size, NO, 
0);
    
else
        UIGraphicsBeginImageContext(size);

    CGContextRef context 
= UIGraphicsGetCurrentContext();

    
// Flip the context because UIKit coordinate system is upside down to Quartz coordinate system
    CGContextTranslateCTM(context, 0.0, height);
    CGContextScaleCTM(context, 
1.0-1.0);

    
// Draw the original image to the context
    CGContextSetBlendMode(context, kCGBlendModeCopy);
    CGContextDrawImage(context, CGRectMake(
0.00.0, width, height), image.CGImage);

    
// Retrieve the UIImage from the current context
    UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    
return imageOut;
}

相关文章: