zoukankan      html  css  js  c++  java
  • IOS图片调整用法bitmap

    学习链接:https://www.jianshu.com/p/8f508f4ffd2c

    直接上代码吧

    //将image图片转化为符合要求的图片

    - (UIImage *)transformImage:(UIImage *)image WithTargetRect:(CGRect) targetRect {

        //将image改为50 * 50pt大小的

        CGSize smallImageSize = CGSizeMake(50.0f, 50.0f);

        //创建一个目标大小的画板

        UIGraphicsBeginImageContextWithOptions(smallImageSize, NO, [[UIScreen mainScreen] scale]);

        //将需要转换的图片画在上面

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

        //保存下来

        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();

        //结束画板

        UIGraphicsEndImageContext();

        

        //创建一个纯色图片

        UIColor *backgroudColor =[UIColor whiteColor];

        UIGraphicsBeginImageContextWithOptions(targetRect.size, NO, [[UIScreen mainScreen] scale]);

        CGContextRef context = UIGraphicsGetCurrentContext();

        

        //设置圆角

        float radius = 8.0f;

        CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:targetRect cornerRadius:radius].CGPath);

        CGContextClip(context);

        

        CGContextSetFillColorWithColor(context, [backgroudColor CGColor]);//填充

        CGContextFillRect(context, targetRect);

        //将smallImage画到纯色背景上

        CGFloat margin = 4.0f;

        [smallImage drawAtPoint:CGPointMake(margin, margin)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        

        return newImage;

    }

  • 相关阅读:
    五。java运算符
    二。java的第一个程序
    四。java常量的学习以及数据类型转换
    修改Launcher源码之快速启动
    Eclipse导入Android项目的方法
    js日期时间控件脚本
    Android中的soundpool小结
    Android GPS (当前位置 & GPS信息更新)
    android利用WebView实现浏览器的封装
    Android选项卡置底的方法
  • 原文地址:https://www.cnblogs.com/caijiaming/p/14024272.html
Copyright © 2011-2022 走看看