========== (one) UIImage 图像 等比例缩放==================================
PicAfterZoomWidth:缩放后图片宽  PicAfterZoomHeight:缩放后图片高 (预定义)

+ (UIImage *)getPicZoomImage:(UIImage *)image {

 

    UIImage *img = image;

    

    int h = img.size.height;

    int w = img.size.width;

    if(h <= PicAfterZoomWidth && w <= PicAfterZoomHeight)

    {

        image = img;

    }

    else 

    {

        float b = (float)PicAfterZoomWidth/w < (float)PicAfterZoomHeight/h ? (float)PicAfterZoomWidth/w : (float)PicAfterZoomHeight/h;

        CGSize itemSize = CGSizeMake(b*w, b*h);

        UIGraphicsBeginImageContext(itemSize);

        CGRect imageRect = CGRectMake(0, 0, b*w, b*h);

        [img drawInRect:imageRect];

        img = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

    }

    return img;

}

 =============== ( two )把图片 圆角 化==================================

 

static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,

                                 float ovalHeight)

{

    float fw, fh;

    if (ovalWidth == 0 || ovalHeight == 0) {

        CGContextAddRect(context, rect);

        return;

    }

    CGContextSaveGState(context);

    CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));

    CGContextScaleCTM(context, ovalWidth, ovalHeight);

    fw = CGRectGetWidth(rect) / ovalWidth;

    fh = CGRectGetHeight(rect) / ovalHeight;

    CGContextMoveToPoint(context, fw, fh/2);  // Start at lower right corner

    CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);  // Top right corner

    CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner

    CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner

    CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right

    CGContextClosePath(context);

    CGContextRestoreGState(context);

}

+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size

{

    // the size of CGContextRef

    int w = size.width;

    int h = size.height;

    

    UIImage *img = image;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace,kCGImageAlphaPremultipliedFirst);

    CGRect rect = CGRectMake(0, 0, w, h);

    CGContextBeginPath(context);

    addRoundedRectToPath(context, rect, 10, 10);

    CGContextClosePath(context);

    CGContextClip(context);

    CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

    CGImageRef imageMasked = CGBitmapContextCreateImage(context);

    CGContextRelease(context);

    CGColorSpaceRelease(colorSpace);

    return [UIImage imageWithCGImage:imageMasked];

}

=============== (Three)给图片 添加阴影==================================

請先添加库 import QuartzCore.framework

然后要导入头文件 #import <QuartzCore/QuartzCore.h>

[[myView layer] setShadowOffset:CGSizeMake(5, 5)]; //设置阴影起点位置

[[myView layer] setShadowRadius:6];                       //设置阴影扩散程度

[[myView layer] setShadowOpacity:1];                      //设置阴影透明度

[[myView layer] setShadowColor:[UIColor blueColor].CGColor]; //设置阴影颜色

 ========== (Four) UIImage 图像 旋转==================================

- (UIImage *)imageRotatedByRadians:(CGFloat)radians

{

    return [self imageRotatedByDegrees:radians * 180/M_PI];

}

- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees 

{   

    // calculate the size of the rotated view's containing box for our drawing space

    UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width,self.size.height)];

    CGAffineTransform t = CGAffineTransformMakeRotation(degrees * M_PI / 180);

    rotatedViewBox.transform = t;

    CGSize rotatedSize = rotatedViewBox.frame.size;

    [rotatedViewBox release];

    // Create the bitmap context

    UIGraphicsBeginImageContext(rotatedSize);

    CGContextRef bitmap = UIGraphicsGetCurrentContext();

    // Move the origin to the middle of the image so we will rotate and scale around the center.

    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);

    

    //   // Rotate the image context

    CGContextRotateCTM(bitmap, degrees * M_PI / 180);

    // Now, draw the rotated/scaled image into the context

    CGContextScaleCTM(bitmap, 1.0, -1.0);

    CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2,self.size.width, self.size.height), [self CGImage]);

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;

}

图像旋转更多请看:http://www.catamount.com/blog/1015/uiimage-extensions-for-cutting-scaling-and-rotating-uiimages/

[转]常用iOS图片处理方法的更多相关文章

  1. iOS 图片压缩方法

    iOS 图片压缩方法 两种图片压缩方法 两种压缩图片的方法:压缩图片质量(Quality),压缩图片尺寸(Size). 压缩图片质量 NSData *data = UIImageJPEGReprese ...

  2. iOS 图片裁剪方法

    iOS 图片裁剪方法 通过 CGImage 或 CIImage 裁剪 UIImage有cgImage和ciImage属性,分别可以获得CGImage和CIImage对象.CGImage和CIImage ...

  3. iOS 图片旋转方法

    iOS 图片旋转方法 通过 CGImage 或 CIImage 旋转特定角度 UIImage可通过CGImage或CIImage初始化,初始化方法分别为init(cgImage: CGImage, s ...

  4. C#常用的图片处理方法-图片剪切、图片压缩、多图合并代码

    /// <summary> /// 图片转成圆角方法二 /// </summary> private Bitmap WayTwo(Bitmap bitmap) { //usin ...

  5. CSS常用背景图片定位方法

    CSS背景图片定位其实对于每一位学习前端的同学来说,都已经非常熟悉了.网上铺天盖地的最常见的一种方案就是在父元素中relative,然后子元素absolute.这种方案当然好,不过带来的一个缺点就是会 ...

  6. ios 图片拉伸方法

     前提:要注意图片的size和展示的图片view的size的大小. 假如图片高度50,展示图片view的高度30,拉伸会变成剪切. 如果图片尺寸不对,可以用mac自带的图片编辑器修改大小: 双击打开图 ...

  7. iOS 图片裁剪 + 旋转

    iOS 图片裁剪 + 旋转 之前分别介绍了图片裁剪和图片旋转方法 <iOS 图片裁剪方法> 地址:http://www.cnblogs.com/silence-cnblogs/p/6490 ...

  8. MATLAB(4)——图片保存方法汇总及常用指令

    作者:桂. 时间:2017-03-03  19:30:03 链接:http://www.cnblogs.com/xingshansi/p/6498318.html 前言 本文为MATLAB系列第四篇. ...

  9. iOS图片加载框架-SDWebImage解读

    在iOS的图片加载框架中,SDWebImage可谓是占据大半壁江山.它支持从网络中下载且缓存图片,并设置图片到对应的UIImageView控件或者UIButton控件.在项目中使用SDWebImage ...

随机推荐

  1. 这一千个Python库,总有你想要的!

    环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex – 可以在虚拟环境中执行命令. v ...

  2. loc与iloc函数的使用

    Pandas中loc和iloc函数用法详解(源码+实例)  https://blog.csdn.net/w_weiying/article/details/81411257 Pandas中loc,il ...

  3. 01 Django基础知识

    相关概念 软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模块都有特定的功能 ...

  4. Python如何查看变量在内存中的地址

    在python中可以用id()函数获取对象的内存地址. 用法: object = 1 + 2 object -- 对象

  5. linux防火墙firewall使用简介

    1.firewalld的基本使用启动: systemctl start firewalld查看状态: systemctl status firewalld停止: systemctl disable f ...

  6. Leetcode 559. N叉树的最大深度

    题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...

  7. Leetcode 814. 二叉树剪枝

    题目链接 https://leetcode-cn.com/problems/binary-tree-pruning/description/ 题目描述 给定二叉树根结点 root ,此外树的每个结点的 ...

  8. CodeForces Round #320 Div2

    A. Raising Bacteria 计算一下x的bitcount就是答案. #include <iostream> #include <cstdio> #include & ...

  9. CodeForces 14D 树的直径 Two Paths

    给出一棵树,找出两条不相交即没有公共点的路径,使得两个路径的长度的乘积最大. 思路:枚举树中的边,将该边去掉,分成两棵树,分别求出这两棵树的直径,乘起来维护一个最大值即可. #include < ...

  10. angularjs报错问题记录

    1.[$injector:unpr]:没有找到注入的东西    2.$compile:multidir:多指令编译错误.    3.[ng:areq]:重复定义了ng-controller.    4 ...