iOS开发CGImage.h简介
1、前因
由于剪切图片用到下面方法,此方法属于CGImage.h中,通过创建CGImageRef像素位图,可以通过操作存储的像素位来编辑图片。
/* Create an image using the data contained within the subrectangle `rect'
of `image'.
截取图像的一个区域重绘图像*/
CG_EXTERN CGImageRef __nullable CGImageCreateWithImageInRect(
CGImageRef cg_nullable image, CGRect rect)
效果图展示:
代码展示:
UIImage *bgImage =[UIImage imageNamed:@""]; // 上半部
UIImageView *topImgView = [[UIImageView alloc] initWithFrame:CGRectMake(, , CScreenWidth, (CScreenHeight-) * 0.5)];
topImgView.image = [self clipImage:bgImage withRect:CGRectMake(, , imageW, imageH)]; // 下半部
UIImageView *bottomImgView = [[UIImageView alloc] initWithFrame:CGRectMake(, +(CScreenHeight-) * 0.5, CScreenWidth, (CScreenHeight-) * 0.5)];
bottomImgView.image = [self clipImage:bgImage withRect:CGRectMake(, imageH, imageW, imageH)];
[self.view addSubview:topImgView];
[self.view addSubview:bottomImgView]; CGAffineTransform transform = CGAffineTransformIdentity;
transform =CGAffineTransformScale(transform, ., .);
[UIView animateWithDuration:2.0f animations:^{
CGRect topRect = topImgView.frame;
topRect.origin.x -= CScreenWidth;
topImgView.frame = topRect;
topImgView.transform = transform; CGRect bottomRect = bottomImgView.frame;
bottomRect.origin.x += CScreenWidth;
bottomImgView.frame = bottomRect;
bottomImgView.transform = transform;
} completion:^(BOOL finished) {
[topImgView removeFromSuperview];
[bottomImgView removeFromSuperview];
}];
- (UIImage *)clipImage:(UIImage *)image withRect:(CGRect)rect {
CGRect clipFrame = rect;
CGImageRef refImage = CGImageCreateWithImageInRect(image.CGImage, clipFrame);
UIImage *newImage = [UIImage imageWithCGImage:refImage];
CGImageRelease(refImage);
return newImage;
}
2、CGImage.h文件方法简介
typedef CF_ENUM(uint32_t, CGImageAlphaInfo) {
kCGImageAlphaNone, /* For example, RGB. */
kCGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */
kCGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */
kCGImageAlphaLast, /* For example, non-premultiplied RGBA */
kCGImageAlphaFirst, /* For example, non-premultiplied ARGB */
kCGImageAlphaNoneSkipLast, /* For example, RBGX. */
kCGImageAlphaNoneSkipFirst, /* For example, XRGB. */
kCGImageAlphaOnly /* No color data, alpha data only */
}; typedef CF_ENUM(uint32_t, CGImageByteOrderInfo) {
kCGImageByteOrderMask = 0x7000,
kCGImageByteOrderDefault = ( << ),
kCGImageByteOrder16Little = ( << ),
kCGImageByteOrder32Little = ( << ),
kCGImageByteOrder16Big = ( << ),
kCGImageByteOrder32Big = ( << )
} CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); typedef CF_OPTIONS(uint32_t, CGBitmapInfo) {
kCGBitmapAlphaInfoMask = 0x1F, kCGBitmapFloatInfoMask = 0xF00,
kCGBitmapFloatComponents = ( << ), kCGBitmapByteOrderMask = kCGImageByteOrderMask,
kCGBitmapByteOrderDefault = kCGImageByteOrderDefault,
kCGBitmapByteOrder16Little = kCGImageByteOrder16Little,
kCGBitmapByteOrder32Little = kCGImageByteOrder32Little,
kCGBitmapByteOrder16Big = kCGImageByteOrder16Big,
kCGBitmapByteOrder32Big = kCGImageByteOrder32Big
} CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); #ifdef __BIG_ENDIAN__
# define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Big
# define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Big
#else /* Little endian. */
# define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Little
# define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Little
#endif /* Return the CFTypeID for CGImageRefs. */
CG_EXTERN CFTypeID CGImageGetTypeID(void) /* Create an image.
width:图片宽度像素
height:图片高度像素
bitsPerComponent:每个颜色的比特数,例如在rgba-32模式下为8
bitsPerPixel:每个像素的总比特数
bytesPerRow:每一行占用的字节数,注意这里的单位是字节
space:颜色空间模式,例如const CFStringRef kCGColorSpaceGenericRGB 这个函数可以返回一个颜色空间对象。
bitmapInfo:位图像素布局
provider:数据源提供者
decode[]:解码渲染数组
shouldInterpolate:是否抗锯齿
intent:图片相关参数*/
CG_EXTERN CGImageRef __nullable CGImageCreate(size_t width, size_t height,
size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow,
CGColorSpaceRef cg_nullable space, CGBitmapInfo bitmapInfo,
CGDataProviderRef cg_nullable provider,
const CGFloat * __nullable decode, bool shouldInterpolate,
CGColorRenderingIntent intent) /* Create an image mask.
创建mask图片图层,可以设置其显示部分与不显示部分达到特殊的效果*/
CG_EXTERN CGImageRef __nullable CGImageMaskCreate(size_t width, size_t height,
size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow,
CGDataProviderRef cg_nullable provider, const CGFloat * __nullable decode,
bool shouldInterpolate) /* Return a copy of `image'. Only the image structure itself is copied; the
underlying data is not.
复制一个CGImageRef对象*/
CG_EXTERN CGImageRef __nullable CGImageCreateCopy(CGImageRef cg_nullable image) /* Create an image from `source', a data provider of JPEG-encoded data.
通过JPEG数据源获取图像 */
CG_EXTERN CGImageRef __nullable CGImageCreateWithJPEGDataProvider(
CGDataProviderRef cg_nullable source, const CGFloat * __nullable decode,
bool shouldInterpolate,
CGColorRenderingIntent intent) /* Create an image using `source', a data provider for PNG-encoded data.
通过PNG数据源获取图像 */
CG_EXTERN CGImageRef __nullable CGImageCreateWithPNGDataProvider(
CGDataProviderRef cg_nullable source, const CGFloat * __nullable decode,
bool shouldInterpolate,
CGColorRenderingIntent intent) /* Create an image using the data contained within the subrectangle `rect'
of `image'.
截取图像的一个区域重绘图像*/
CG_EXTERN CGImageRef __nullable CGImageCreateWithImageInRect(
CGImageRef cg_nullable image, CGRect rect) /* Create a new image from `image' masked by `mask', which may be an image
mask or an image.
截取mask图像的某个区域重绘图像 */
CG_EXTERN CGImageRef __nullable CGImageCreateWithMask(
CGImageRef cg_nullable image, CGImageRef cg_nullable mask) /* Create a new image from `image' masked by `components'
通过颜色分量数组创建位图*/
CG_EXTERN CGImageRef __nullable CGImageCreateWithMaskingColors(
CGImageRef cg_nullable image, const CGFloat * cg_nullable components) /* Create a copy of `image', replacing the image's color space with `space'.
Returns NULL if `image' is an image mask, or if the number of components
of `space' isn't the same as the number of components of the color space
of `image'.
通过颜色空间模式复制位图*/
CG_EXTERN CGImageRef __nullable CGImageCreateCopyWithColorSpace(
CGImageRef cg_nullable image, CGColorSpaceRef cg_nullable space) /* Equivalent to `CFRetain(image)'.
引用计数+1*/
CG_EXTERN CGImageRef cg_nullable CGImageRetain(CGImageRef cg_nullable image) /* Equivalent to `CFRelease(image)'.
引用计数-1*/
CG_EXTERN void CGImageRelease(CGImageRef cg_nullable image) /* Return true if `image' is an image mask, false otherwise.
是否是mask图层 */
CG_EXTERN bool CGImageIsMask(CGImageRef cg_nullable image) /* Return the width of `image'.
获取图像宽度像素*/
CG_EXTERN size_t CGImageGetWidth(CGImageRef cg_nullable image) /* Return the height of `image'.
获取图像的高度像素*/
CG_EXTERN size_t CGImageGetHeight(CGImageRef cg_nullable image) //获取图像相应属性
/* Return the number of bits/component of `image'. */
CG_EXTERN size_t CGImageGetBitsPerComponent(CGImageRef cg_nullable image)
/* Return the number of bits/pixel of `image'. */
CG_EXTERN size_t CGImageGetBitsPerPixel(CGImageRef cg_nullable image)
/* Return the number of bytes/row of `image'. */
CG_EXTERN size_t CGImageGetBytesPerRow(CGImageRef cg_nullable image)
/* Return the color space of `image', or NULL if `image' is an image
mask. */
CG_EXTERN CGColorSpaceRef __nullable CGImageGetColorSpace(CGImageRef cg_nullable image)
/* Return the alpha info of `image'. */
CG_EXTERN CGImageAlphaInfo CGImageGetAlphaInfo(CGImageRef cg_nullable image)
/* Return the data provider of `image'. */
CG_EXTERN CGDataProviderRef __nullable CGImageGetDataProvider(CGImageRef cg_nullable image)
/* Return the decode array of `image'. */
CG_EXTERN const CGFloat * __nullable CGImageGetDecode(CGImageRef cg_nullable image)
/* Return the interpolation parameter of `image'. */
CG_EXTERN bool CGImageGetShouldInterpolate(CGImageRef cg_nullable image)
/* Return the rendering intent of `image'. */
CG_EXTERN CGColorRenderingIntent CGImageGetRenderingIntent(cg_nullable CGImageRef image)
/* Return the bitmap info of `image'. */
CG_EXTERN CGBitmapInfo CGImageGetBitmapInfo(CGImageRef cg_nullable image)
/* Return the UTType of `image'. */
CG_EXTERN CFStringRef __nullable CGImageGetUTType(cg_nullable CGImageRef image)
iOS开发CGImage.h简介的更多相关文章
- iOS开发UIView.h简介
1.UICoordinateSpace不同坐标空间的坐标切换 @protocol UICoordinateSpace <NSObject> //将当前的坐标空间点转换到指定的坐标空间 - ...
- iOS开发UIEvent事件简介
1.UIEvent简介 UIEvent是代表iOS系统中的一个事件,一个事件包含一个或多个的UITouch: UIEvent分为四类: UIEventType typedef NS_ENUM(NSIn ...
- iOS开发CATransform3D.h属性详解和方法使用
1.CATransform3D简介 layer有个属性transform,是CATransform3D类型.可以使其在三维界面作平移.缩放和旋转单独或组合动画! CATransform3D结构体: / ...
- iOS开发UI篇—CALayer简介
iOS开发UI篇—CALayer简介 一.简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView. 其实 ...
- iOS开发UI篇—核心动画简介
转自:http://www.cnblogs.com/wendingding/p/3801036.html iOS开发UI篇—核心动画简介 一.简单介绍 Core Animation,中文翻译为核心动画 ...
- iOS开发多线程篇—多线程简介
iOS开发多线程篇-多线程简介 一.进程和线程 1.什么是进程 进程是指在系统中正在执行的一个应用程序 每一个进程之间是独立的.每一个进程均执行在其专用且受保护的内存空间内 比方同一时候打开QQ.Xc ...
- XMPPFrameWork IOS 开发(一)xmpp简介
原始地址:XMPPFrameWork IOS 开发(一) XMPP : The Extensible Messaging and Presence Protocol 中文全称: 可扩展通讯和表示协议 ...
- iOS开发中KVC、KVO简介
在iOS开发中,KVC和KVO是经常被用到的.可以使用KVC对对象的属性赋值和取得对象的属性值,可以使用KVO监听对象属性值的变化.简单介绍一下KVC和KVO. 一:键值编码(KVC) KVC,全称 ...
- iOS开发多线程篇—GCD简介
iOS开发多线程篇—GCD介绍 一.简单介绍 1.什么是GCD? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD的优势 G ...
随机推荐
- 使用python和tushare股票交易日历数据,判断节假日周末休市
接口:trade_cal 描述:获取各大交易所交易日历数据,默认提取的是上交所 注:tushare模块下载和安装教程,请查阅我之前的文章 输入参数 名称 | 类型 ...
- Java笔记之public、protected、default和private
参考链接:private public protected default区别 - Ma_xiao_shuai的博客 - CSDN博客
- 安装go环境
~~~~~~~~~~~~~~~~~~~~~~~~~~~~go项目运行时的依赖包安装问题~~~~~~~~~~~~~~~~~~~~~~~~~~~~1.安装go环境 wget https://dl.goog ...
- Spring-Boot中如何使用多线程处理任务
看到这个标题,相信不少人会感到疑惑,回忆你们自己的场景会发现,在Spring的项目中很少有使用多线程处理任务的,没错,大多数时候我们都是使用Spring MVC开发的web项目,默认的Controll ...
- 【转】ArcObject与ArcEngine的联系与区别
在ArcGIS系列产品中,ArcGIS Desktop.ArcGIS Engine和ArcGIS Server都是基于核心组件库ArcObjects搭建的. 所谓ArcObjects,现在一般都是指A ...
- centos7使用iptables作为防火墙方法
centos7使用iptables作为防火墙方法查看firewalld状态: systemctl status firewalld将centos7默认的firewalld停止,并将iptables作为 ...
- leetcode-229-求众数②
题目描述: 方法一:摩尔投票法 class Solution: def majorityElement(self, nums: List[int]) -> List[int]: candiate ...
- CNN 常用的几个模型
LeNet5 论文:http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf LeNet-5:是Yann LeCun在1998年设计的用于手写数字识别的卷 ...
- c# 中Linq Lambda 的ToLookup方法的使用
同样直接上代码: List<Student> ss = new List<Student>(); Student ss1 = , Age = , Name = " } ...
- 杂项-语言-Swift:Swift
ylbtech-杂项-语言-Swift:Swift Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于 ...