image处理相关
发布日期:2022-03-18 08:27:35
浏览次数:35
分类:技术文章
本文共 2068 字,大约阅读时间需要 6 分钟。
image做遮罩mask
原理性的东西请参考,也可以参考
请参考:
实现方式是:
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); return [UIImage imageWithCGImage:masked];}
另一种方式会使用到
CGContextClipToMask(context, self.bounds, mask);
例如例子中,利用mask来实现一个渐变的圆圈
-(void)drawEllipseWithGradient:(CGContextRef)context{ CGContextSaveGState(context); //UIGraphicsBeginImageContextWith(self.frame.size); UIGraphicsBeginImageContextWithOptions((self.frame.size), NO, 0.0); CGContextRef newContext = UIGraphicsGetCurrentContext(); //Set color of current context [[UIColor blackColor] set]; //Draw ellipse <- I know we’re drawing a circle, but a circle is just a special ellipse. CGRect ellipseRect = CGRectMake(110.0f, 200.0f, 100.0f, 100.0f); CGContextFillEllipseInRect(newContext, ellipseRect); CGImageRef mask = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext()); UIGraphicsEndImageContext(); CGContextClipToMask(context, self.bounds, mask); [self drawGradient:context]; CGImageRelease(mask); CGContextRestoreGState(context);}
中的例子也一样
UIImage *iconImage = [UIImage imageNamed:@"logo.png"];UIImage *maskImage = [UIImage imageNamed:@"mask.png"];UIGraphicsBeginImageContext(iconImage.size);//設定參考範圍CGContextRef context = UIGraphicsGetCurrentContext();CGContextScaleCTM(context, 1, -1);CGRect region = CGRectMake(0, 0, iconImage.size.width, iconImage.size.height);CGContextTranslateCTM(context, 0, -region.size.height);//將context做遮罩範圍的切割再drawCGContextClipToMask(context, region, maskImage.CGImage);CGContextDrawImage(context, region, iconImage.CGImage);//將影像指定給imageViewimageView.image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();
转载地址:https://windzen.blog.csdn.net/article/details/48495459 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年03月11日 11时06分43秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
mysql like 数字结尾_重拾MySQL之正则表达式
2019-04-21
mysql 重置密码_mysql忘记密码如何重置密码,以及修改root密码的三种方法
2019-04-21
python中两个时间相减结果转为小时_Python起步(二)基础数据类型1
2019-04-21
定义泛化。举个例子_网易考拉应用的dubbo泛化调用,是如何实现的?
2019-04-21
mysql里可以用cube吗_sql server的cube操作符使用详解_mysql
2019-04-21
php mysql 图书_使用PHP+MySQL来对图书管理系统进行构建
2019-04-21
单片机c语言 int1,51单片机into、int1中断计数c语言源程序.doc
2019-04-21
c语言课程设计工资管理建库,C语言课程设计工资管理系统参考.doc
2019-04-21
c51写c语言外部ram头文件,C51中访问外部RAM的方法
2019-04-21
c语言打开一个html文件路径,C语言文件处理-C语言文件的打开和关闭
2019-04-21
普职融通信息技术课本C语言,“三步走”扎实推进“普职融通”办学新模式
2019-04-21
Android多个签名,【Android】Android批量重签名
2019-04-21
html unicode编码转换,JS实现的Unicode编码转换操作示例
2019-04-21
html页面角落放动漫人物,L2Dwidget.js L2D网页动画人物添加
2019-04-21
html图片水平居中,CSS制作图片水平垂直居中
2019-04-21