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;
}

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2021-12-19
  • 2021-09-21
猜你喜欢
  • 2021-06-14
  • 2021-07-25
  • 2021-10-23
  • 2022-12-23
  • 2021-12-13
  • 2021-07-07
相关资源
相似解决方案