zoukankan      html  css  js  c++  java
  • ios-改变图片的尺寸

    //改变图片的尺寸

    -(UIImage*) OriginImage:(UIImage *)image scaleToSize:(CGSize)size

    {

        UIGraphicsBeginImageContext(size);  //size 为CGSize类型,即你所需要的图片尺寸

        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        UIImage *imagescaless=  [self imageRetain:scaledImage];

        return imagescaless;   //返回的就是已经改变的图片

    }

    //对.2x图片进行处理

    -(UIImage*)imageRetain:(UIImage *)sourceImage

    {

        CGSize size;

        size = CGSizeMake(sourceImage.size.width / 2.0f, sourceImage.size.height / 2.0f);

        UIGraphicsBeginImageContextWithOptions(size, NO, 0);

        if (1.0 == [[UIScreen mainScreen] scale]){

            [sourceImage drawInRect:CGRectIntegral((CGRect){0.0f, 0.0f, size})];

        }else{

            [sourceImage drawInRect:(CGRect){0.0f, 0.0f, size}];

            sourceImage = UIGraphicsGetImageFromCurrentImageContext();

            UIGraphicsEndImageContext();

        }

        return sourceImage;

    }

    下面是调用方法:

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        _dataList=[[NSMutableArray alloc]initWithCapacity:10];

        [self initViews];

        

        NSArray *tmpArray1 = @[@"照片墙",@"讨论区",@"群组",@"通讯录"];

        self.SXHAry = tmpArray1;

        

        NSArray *tmpArray2 = @[@"晚报放心购",@"厦门房产动态",@"厦门车市动态"];

        self.XMRBAry = tmpArray2;

        

        NSArray *bFirsts = @[@"gc1.png",@"gc2.png",@"gc3.png",@"gc4.png"];

        

        NSMutableArray *bFirst=[[NSMutableArray alloc]initWithCapacity:0];

        for (int i=0; i<bFirsts.count; i++) {

            UIImage*images=[UIImage imageNamed:[bFirsts objectAtIndex:i]];

            UIImage *imagenew=[self OriginImage:images scaleToSize:CGSizeMake(45, 45)];

            [bFirst addObject:imagenew];

        }

        self.bFirstAry = [bFirst copy];

        

        NSArray *bSecconds = @[@"gc6.png",@"gc7.png",@"gc8.png"];

        NSMutableArray *bSecond=[[NSMutableArray alloc]initWithCapacity:0];

        for (int i=0; i<bSecconds.count; i++) {

            UIImage*images=[UIImage imageNamed:[bSecconds objectAtIndex:i]];

            UIImage *imagenew=[self OriginImage:images scaleToSize:CGSizeMake(45, 45)];

            [bSecond addObject:imagenew];

        }

        self.bSecondAry = [bSecond copy];

        

        NSArray *rFirsts = @[@"gc1.png",@"gc2.png",@"gc3.png",@"gc4.png"];

        NSMutableArray *rFirst=[[NSMutableArray alloc]initWithCapacity:0];

        for (int i=0; i<rFirsts.count; i++) {

            UIImage*images=[UIImage imageNamed:[rFirsts objectAtIndex:i]];

            UIImage *imagenew=[self OriginImage:images scaleToSize:CGSizeMake(45, 45)];

            [rFirst addObject:imagenew];

        }

        self.rFirstAry = [rFirst copy];

        

        NSArray *rSeconds = @[@"gc6.png",@"gc7.png",@"gc8.png"];

        NSMutableArray *rSecond=[[NSMutableArray alloc]initWithCapacity:0];

        for (int i=0; i<rSeconds.count; i++) {

            UIImage*images=[UIImage imageNamed:[rSeconds objectAtIndex:i]];

            UIImage *imagenew=[self OriginImage:images scaleToSize:CGSizeMake(45, 45)];

            [rSecond addObject:imagenew];

        }

        self.rSecondtAry = [rSecond copy];

        [self setExtraCellLineHidden:self.squareTableCell];

    }

  • 相关阅读:
    Codeforces Round #344 (Div. 2) C. Report 其他
    Codeforces Round #344 (Div. 2) B. Print Check 水题
    Codeforces Round #344 (Div. 2) A. Interview 水题
    8VC Venture Cup 2016
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂 中二版
    CDOJ 1280 772002画马尾 每周一题 div1 矩阵快速幂
    CDOJ 1279 班委选举 每周一题 div2 暴力
    每周算法讲堂 快速幂
    8VC Venture Cup 2016
    Educational Codeforces Round 9 F. Magic Matrix 最小生成树
  • 原文地址:https://www.cnblogs.com/xm5mao/p/3964701.html
Copyright © 2011-2022 走看看