在iOS中绘制加载的UIImage

在iOS中绘制加载的UIImage,第1张

概述我有一些问题. 我有一个加载的UIImage,我想: 1 – 在我加载的UIImage上绘制另一张图像 第二步 – 在我加载的UIImage上画一条线(有颜色和粗细) 如果你能想出一些基本的东西,我会非常感激,我还是一个菜鸟:) 还有另一种选择,它使用核心图形. UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);CGContextRef 我有一些问题.

我有一个加载的UIImage,我想:

1 – 在我加载的UIImage上绘制另一张图像

第二步 – 在我加载的UIImage上画一条线(有颜色和粗细)

如果你能想出一些基本的东西,我会非常感激,我还是一个菜鸟:)

解决方法 还有另一种选择,它使用核心图形.

UIGraphicsBeginImageContextWithOptions(size,NO,0.0);CGContextRef context = UIGraphicsGetCurrentContext();CGContextSaveGState(context);UIImage *bottomImage = ...;CGRect bottomImageRect = ...;CGContextScaleCTM(context,1.0,-1.0);CGContextTranslateCTM(context,-bottomImageRect.size.height);CGContextDrawImage(context,bottomImageRect,bottomImage.CGImage);CGContextRestoreGState(context);CGContextSaveGState(context);UIImage *topImage = ...;CGRect topImageRect = ...;CGContextScaleCTM(context,-topImageRect.size.height);CGContextDrawImage(context,topImageRect,topImage.CGImage);CGContextRestoreGState(context);CGPoint origin = ...;CGPoint end = ...;CGContextMovetoPoint(context,origin.x,origin.y);CGContextAddlinetoPoint(context,end.x,end.y);CGContextSetstrokecolorWithcolor(context,[UIcolor whatever].CGcolor);CGContextstrokePath(context);UIImage *result = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();

编辑:稍微更改了代码,使图像不会反转

总结

以上是内存溢出为你收集整理的在iOS中绘制加载的UIImage全部内容,希望文章能够帮你解决在iOS中绘制加载的UIImage所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1038602.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存