编辑图片的几个方法
第一种
先用UIImage对象加载一张图片
然后转化成CGImageRef放到CGContext中去编辑
第二种 
用CGImageCreate函数创建CGImageRef
然后把CGImageRef放到CGContext中去编辑
第三种
用CGImageCreateCopy 或者 CGImageCreateCopyWithColorSpace
函数拷贝
CGImageRef CGImageCreate (
   size_t width, //图片的宽度
   size_t height, //图片的高度
   size_t bitsPerComponent,
//图片每个颜色的bits,比如rgb颜色空间,有可能是5 或者 8 ==
   size_t bitsPerPixel,
//每一个像素占用的buts,15 位24位 32位等等
   size_t bytesPerRow, //每一行占用多少bytes 注意是bytes不是bits  1byte = 8bit
   CGColorSpaceRef colorspace,
//颜色空间,比如rgb
   CGBitmapInfo bitmapInfo,
//layout ,像素中bit的布局, 是rgba还是 argb,==
   CGDataProviderRef provider,
//数据源提供者,url或者内存==
   const CGFloat decode[],
//一个解码数组
   bool shouldInterpolate,
//抗锯齿参数
   CGColorRenderingIntent intent
//图片渲染相关参数
);
创建 image mask的一个途径
CGImageMaskCreate
给图片加mask有两种方法,
第一种
使用函数 CGImageCreateWithMask 或者 CGImageCreateWithMaskingColors 在图片上直接打上mask
这样做对原来的图片要求带有 alpha通道,假如没有,那么不会有半透明的效果
第二种
使用 CGContextClipToMask 在图形上下问的某个矩形区域打上mask,这样做无论原先的图片有没有alpha通道,都可以实现半透明效果
位图永远是矩形形状的
iphone支持图片格式:
JPEG, GIF, PNG, TIF, ICO, GMP, XBM, and CUR.
创建一张图片,我们需要提供的一些东西
A bitmap data source
An optional Decode Array, 这个数组在渲染的时候会应用在每一个像素上面,是一个颜色变成另外一个颜色。
An interpolation setting, 布尔值,缩放图片的时候是否采用interpolation算法,具体这个算法不怎么了解
渲染意向
图片尺寸
Pixel Format:这个包括3个东西,
1,Bits per component,每一个component有多少Bits
2. Bits per pixel, 每一个像素占多少Bits
3. Bytes per row,每一个占多少Bytes
Color Spaces and Bitmap Layout,这里需要提供的几个东西
1,Whether a bitmap contains an alpha channel. 位图是否包含alpha通道
2。 color components是否已经乘以alpha value
3。数据格式是浮点数还是整型
Bitmap Layout是指color components的指是怎么指定的
下面的参数 bitmapInfo就是 Bitmap Layout
 
CGImageRef CGImageCreate (
   size_t width,
   size_t height,
   size_t bitsPerComponent,
   size_t bitsPerPixel,
   size_t bytesPerRow,
   CGColorSpaceRef colorspace,
   CGBitmapInfo bitmapInfo,
   CGDataProviderRef provider,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);
选择一个函数来创建图像
CGImageRef CGImageCreate (
   size_t width,
   size_t height,
   size_t bitsPerComponent,
   size_t bitsPerPixel,
   size_t bytesPerRow,
   CGColorSpaceRef colorspace,
   CGBitmapInfo bitmapInfo,
   CGDataProviderRef provider,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);
这个是比较万能的函数,但是提供的参数也是非常的多
 
CGImageRef CGImageCreateWithJPEGDataProvider (
   CGDataProviderRef source,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);
从jpeg源中创建图像
CGImageRef CGImageCreateWithPNGDataProvider (
   CGDataProviderRef source,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);
从png源中创建图像
CGImageRef CGImageCreateWithImageInRect (
   CGImageRef image,
   CGRect rect
);
从一张图片的某块区域创建图片,类似截图
CGImageRef CGImageSourceCreateImageAtIndex (
   CGImageSourceRef isrc,
   size_t index,
   CFDictionaryRef options
);
从一个图片源中创建图片,这个图片源可能包含不止一张图片,0表示第一张
CGImageRef CGImageSourceCreateThumbnailAtIndex (
   CGImageSourceRef isrc,
   size_t index,
   CFDictionaryRef options
);
创建一个缩略图从一个图片源中,这个图片源可能包含不止一张图片,0表示第一张
CGImageRef CGBitmapContextCreateImage (
   CGContextRef c
);
从一个图形上下文中创建图片
 
CGImageRef CGImageCreateCopy (
   CGImageRef image
);
拷贝一张图片
CGImageRef CGImageCreateCopyWithColorSpace (
   CGImageRef image,
   CGColorSpaceRef colorspace
);
拷贝一张图片,替换原来的颜色空间
 
 
 
从jpeg创建图片
void MyCreateAndDrawBitmapImage (CGContextRef myContext, 
                                CGRect myContextRect,
                                const char *filename);
{
    CGImageRef image;
    CGDataProviderRef provider;
    CFStringRef path;
    CFURLRef url;
 
    path = CFStringCreateWithCString (NULL, filename,
                        kCFStringEncodingUTF8);
    url = CFURLCreateWithFileSystemPath (NULL, path, // 2
                            kCFURLPOSIXPathStyle, NO);
    CFRelease(path);
    provider = CGDataProviderCreateWithURL (url);// 3
    CFRelease (url);
    image = CGImageCreateWithJPEGDataProvider (provider,// 4
                                    NULL,
                                    true,
                                    kCGRenderingIntentDefault);
    CGDataProviderRelease (provider);// 5
    CGContextDrawImage (myContext, myContextRect, image);// 6
    CGImageRelease (image);// 7
}
CGImageRef CGImageMaskCreate (
        size_t width,
        size_t height,
        size_t bitsPerComponent,
        size_t bitsPerPixel,
        size_t bytesPerRow,
        CGDataProviderRef provider,
        const float decode[],
        int shouldInterpolate
);
从一个已经存在的图形上下文中创建一个CGLayerRef
CGLayerRef CGLayerCreateWithContext (
   CGContextRef context,
   CGSize size,
   CFDictionaryRef auxiliaryInfo
);
CGSize CGLayerGetSize (
   CGLayerRef layer
);
然后从CGLayerRef中得到CGContextRef,就是图形上下文
CGContextRef CGLayerGetContext (
   CGLayerRef layer
);
接着在这个CGContextRef中绘画
Draw the CGLayer to the Destination Graphics Context
void CGContextDrawLayerInRect (
   CGContextRef context,
   CGRect rect,
   CGLayerRef layer
);
void CGContextDrawLayerAtPoint (
   CGContextRef context,
   CGPoint point,
   CGLayerRef layer
);

版权声明:本文为博主原创文章,未经博主允许不得转载。

IOS-图片操作集合的更多相关文章

  1. 实现iOS图片等资源文件的热更新化(三):动态的资源文件夹

    简介 此文,将尝试动态从某个不确定的文件夹中加载资源文件.文章,会继续完善自定义的 imageNamed 函数,并为下一篇文章铺垫. 这么做的意义 正如我们经常所说的那样,大多数情景知道做事的意义往往 ...

  2. 实现iOS图片等资源文件的热更新化(五): 一个简单完整的资源热更新页面

    简介 一个简单的关于页面,有一个图片,版本号,App名称等,着重演示各个系列的文章完整集成示例. 动机与意义 这是系列文章的最后一篇.今天抽空写下,收下尾.文章本身会在第四篇的基础上,简单扩充下代码, ...

  3. 实现iOS图片等资源文件的热更新化(零): 序

    必要的序 以后在写系列文章,准备把基本的规划和动机等,单独作为一个小的序言部分给独立出来.序言部分,可以较为完整地交待系列文章的写作动机,所展示的编码技术可能的应用场景等.个人,我还是比较看重文章或者 ...

  4. 大屏iPhone的适配 +iOS 图片尺寸要求

    摘自:http://blog.ibireme.com/2014/09/16/adapted_to_iphone6/ 苹果公司官网设计介绍到:Retina显示屏的超高像素密度已超过人眼能分辨的范围.Re ...

  5. js 前端图片压缩+ios图片角度旋转

    step1:读取选择的图片,并转为base64: function ImgToBase64 (e, fn) { // 图片方向角 //fn为传入的方法函数,在图片操作完成之后执行 var Orient ...

  6. C#——图片操作类简单封装

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...

  7. iOS 线程操作库 PromiseKit

    iOS 线程操作库 PromiseKit 官网:http://promisekit.org/ github:https://github.com/mxcl/PromiseKit/tree/master ...

  8. iOS 图片的解压缩

    一.图片加载的工作流 概括来说,从磁盘中加载一张图片,并将它显示到屏幕上,中间的主要工作流如下: 假设我们使用 +imageWithContentsOfFile: 方法从磁盘中加载一张图片,此时的图片 ...

  9. iOS 图片加载速度优化

    FastImageCache 是 Path 团队开发的一个开源库,用于提升图片的加载和渲染速度,让基于图片的列表滑动起来更顺畅,来看看它是怎么做的. 一.优化点 iOS 从磁盘加载一张图片,使用 UI ...

  10. ECharts外部调用保存为图片操作及工作流接线mouseenter和mouseleave由于鼠标移动速度过快导致问题解决办法

    记录两个项目开发中遇到的问题,一个是ECharts外部调用保存为图片操作,一个是workflow工作流连接曲线onmouseenter和onmouseleave事件由于鼠标移动过快触发问题. 一.外部 ...

随机推荐

  1. POJ 1743 Musical Theme(不可重叠最长重复子串)

    题目链接:http://poj.org/problem?id=1743 题意:有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一 ...

  2. 5.4.2 RegExp实例方法

    RegExp对象的主要方法是exec(),该方法是专门为辅助组而设计的.exec()接受一个参数,即要应用模式的字符串,然后返回包含第一个匹配项信息的数组:或者在没有匹配项的情况下返回null.返回的 ...

  3. lambda, reduce, map求阶乘之和

    学完这几个优雅的内建函数,就可以做一些有趣的小练习来激发兴趣了.而python最大的好处便是简洁,看下边要求 用1行代码求 1! + 2! + 3! + ... + 10! 求阶乘 reduce函数用 ...

  4. React使用笔记2-React Components的生命周期

    Date: 2015-11-27 21:23 Category: Web Tags: JavaScript Author: 刘理想 [toc] 1. React Components的生命周期 Rea ...

  5. IPv6地址的ping、telnet等操作

    最近在研究https协议是如何传输数据的,用wireshark抓包分析,发现客户机和google网站在传输数据时使用了IPv6地址,于是相对ipv6地址测试下基本的功能. ping功能,直接使用pin ...

  6. Win32 GDI基础(笔记)

    1.GDI名字的意义 GDI Graphic Device Interface,我说不清和GUI有什么区别.可能一种针对设备,一种针对用户而言吧,反正以后都说GDI,也就是Windows的图形编程. ...

  7. [转]chrome技术文档列表

    chrome窗口焦点管理系统 http://www.douban.com/note/32607279/ chrome之TabContents http://www.douban.com/note/32 ...

  8. JAVA GUI学习 - JInternalFrame浮动窗口:可拖拽窗口(依赖于父窗口)

    public class JInternalFrameKnow extends JInternalFrame { public JInternalFrameKnow() { this.setBound ...

  9. Laravel + Xdebug 时需要注意的问题

    [平台环境]64bit Win7 + Wamp2.5 (php 5.5, Apache 2.4.9) [Xdebug版本]php_xdebug-2.2.5-5.5-vc11-x86_64.dll 配置 ...

  10. Objective-c 类接口 (@interface) (类定义)

    在Objective-c中如何定义一个类呢?我们可以使用下面的格式进行表示: @interface 类名:父类名{ 变量定义; } 方法定义: @end; 下面给出一个实例: @interface P ...