========== (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. [LUOGU] P2634 [国家集训队]聪聪可可

    点分治裸题,甚至不需要栈回撤. 尝试用容斥写了一波,就是把所有子树混一块计算,最后减去子树内路径条数. #include<iostream> #include<cstring> ...

  2. (74)zabbix第三方认证之http(nginx basic auth)

    HTTP Basic Auth认证方式,我们将在实例中使用nginx来演示,Apache也类似. zabbix认证配置 Administration>> Authentication,将h ...

  3. 地理位置编码geohash学习笔记

    1.geohash及其性质 一种空间索引技术. (1)将二维的经纬度位置数据转换为一维的字符串(基本上hash族的算法都是这样): 其优点在于hash编码后的字符串,可以方便查找和索引,从而减少相似计 ...

  4. 《Spring源码深度解析》第三章 默认标签的解析

    上一章提到了,默认标签和自定义标签要分开解析.本章重点介绍默认标签的解析.在 DefaultBeanDefinitionDocumentReader 中: private void parseDefa ...

  5. matplotlib学习记录 一

    from matplotlib import pyplot as plt # 先实例一个图片,传入图片参数,10宽,5高,分辨率为80 image = plt.figure(figsize=(10,5 ...

  6. 掌握这些Python代码技巧,编程至少快一半!

    被人工智能捧红的 Python 已是一种发展完善且非常多样化的语言,其中肯定有一些你尚未发现的功能.本文或许能够让你学到一些新技巧. ​ Python 是世界上最流行.热门的编程语言之一,原因很多,比 ...

  7. LeetCode(234) Palindrome Linked List

    题目 Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) t ...

  8. 牛客网 Wannafly挑战赛21 灯塔

    Z市是一座港口城市,来来往往的船只依靠灯塔指引方向.在海平面上,存在n个灯塔.每个灯塔可以照亮以它的中心点为中心的90°范围.特別地, 由于特殊限制,每个灯塔照亮范围的角的两条边必须要么与坐标轴平行要 ...

  9. Mysql显示某个数据库的所有表

    显示表名: show tables; //先用use进入要查看表的库 mysql> use mysql; Database changed mysql> show tables; +--- ...

  10. webdriver高级应用- 右键另存为下载文件

    1.要使用右键另存,需要先按照第三方工具AutoIt: 链接: https://pan.baidu.com/s/12aBBhOOTmyQpH9hukt0XGA 密码: fcdk 2.创建一个名为loa ...