编辑图片的几个方法
第一种
先用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. SSIS 实例 从Ftp获取多个文件并对数据库进行增量更新。

    整个流程 Step 1 放置一个FTP Task 将远程文件复制到本地 建立FTP链接管理器后 Is LocalPatchVariable 设置为Ture 并创建一个变量设置本地路径 Operatio ...

  2. 【转】Qt Mode/View

    1.view与Widget 在UI中,最常用的就是list/grid/tree了(在Qt中,grid被称为table).尤其是做那些数据库相关的程序,可能每个界面都要用到 list或grid.在Qt中 ...

  3. JBoss 系列二十一:JBossCache核心API

    内容简介 本处介绍JBossCache相关的主要API,我们目的通过本部分描述,读者可以使用JBossCache API,在自己的应用中使用JBossCache. Cache接口 Cache 接口是和 ...

  4. 0527 python 基础01

    折行的处理 \>>> print "hi \... hello Lucy!"hi hello Lucy! 自然字符串,字符串加上r或R前缀指定>>&g ...

  5. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  6. ie7下div覆盖在iframe上方,ie8就不行,怎么解决

    <div style="position:relative;display:inline-block;width:178px;height:90px;z-index:9999;top: ...

  7. VB6.0快捷键大全(转)

    窗体设置,控件布局时用: alt+v+x可以快速显示出工具框 Alt+P+N 引用 ctrl+左右键头可以移动控件 shift+左右键头调整控件大小 F7   切换到编辑窗口 Shift+f7 切换代 ...

  8. [Windows编程] 开发DLL必读《Best Practices for Creating DLLs》

    开发DLL的时候,需要十分注意 DllMain 函数,因为在多线程环境下DLLMain里面的代码很容易引发线程死锁. 这篇MSDN文章<Best Practices for Creating D ...

  9. File,FileInputStream,FileReader,InputStreamReader,BufferedReader 的使用和区别

    1 ) File 类介绍 File 类封装了对用户机器的文件系统进行操作的功能.例如,可以用 File 类获得文件上次修改的时间移动, 或者对文件进行删除.重命名.换句话说,流类关注的是文件内容,而 ...

  10. 用Html5结合Qt制作一款本地化EXE游戏-太空大战(Space War)

    本次来说一说如何利用lufylegend.js引擎制作一款html5游戏后将其通过Qt转换成EXE程序.步骤其实非常简单,接下来就一步步地做一下解释和说明. 首先我们来开发一个有点类似于太空大战的游戏 ...