zoukankan      html  css  js  c++  java
  • iOS 图片比例缩放

    方法

    //Resize image
    
    - (UIImage *)resizeImage:(UIImage *)image
                 withQuality:(CGInterpolationQuality)quality
                        rate:(CGFloat)rate
    {
    	UIImage *resized = nil;
    	CGFloat width = image.size.width * rate;
    	CGFloat height = image.size.height * rate;
    	
    	UIGraphicsBeginImageContext(CGSizeMake(width, height));
    	CGContextRef context = UIGraphicsGetCurrentContext();
    	CGContextSetInterpolationQuality(context, quality);
    	[image drawInRect:CGRectMake(0, 0, width, height)];
    	resized = UIGraphicsGetImageFromCurrentImageContext();
    	UIGraphicsEndImageContext();
    	
    	return resized;
    }
    

      

    使用

    UIImageView *theImageView = [[UIImageView alloc]init];
        
        theImageView.frame = CGRectMake(0, 64, 320, 400);
        
        UIImage *aImage = [UIImage imageNamed:@"shenlin.png"];
        
        UIImage *resizeImage = [self resizeImage:aImage withQuality:kCGInterpolationNone rate:0.2];
        theImageView.image = resizeImage;
        theImageView.frame = CGRectMake(0, 64, resizeImage.size.width, resizeImage.size.height);
        NSLog(@"%@",NSStringFromCGSize(resizeImage.size));
        
        [self.view addSubview:theImageView];
    

      

  • 相关阅读:
    django模型系统(二)
    css基础
    css进阶
    django模型系统(一)
    自定义过滤器及标签
    django模板标签
    模板变量及模板过滤器
    第六章 异常
    第三章:多态
    第三章:提高系统性能:从数据访问开始
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3382486.html
Copyright © 2011-2022 走看看