Tag: cgcontext

合并两个不同大小的图像旋转和缩放

我面临以下问题:我必须合并两个图像bottomImg和topImg,以创build一个新的图像C作为合并的结果。 我已经知道如何合并两个图像,但在这种情况下,我的目标有点不同。 顶部图像可能被缩放和旋转。 我已经按照这个答案 。 但是在这个解决scheme中,当我旋转时,顶部图像被剪切 模拟器 实际存储的图像是像文件一样 我已经尝试这个代码 bottomImg的_parentViewGIf和topImg的_ivGIF – (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg { float width=bottomImg.size.width*_ivGIF.frame.size.width/_parentViewGIf.frame.size.width; float height=bottomImg.size.width*_ivGIF.frame.size.height/_parentViewGIf.frame.size.width; UIImage * scaledTopImg = [self imageByScalingProportionallyWithImage:topImg ToSize:CGSizeMake(bottomImg.size.width, bottomImg.size.height)]; UIGraphicsBeginImageContext(scaledTopImg.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(ctx, scaledTopImg.size.height * 0.5, scaledTopImg.size.height * 0.5); CGFloat angle = atan2(_ivGIF.transform.a, _ivGIF.transform.b); CGContextRotateCTM(ctx, angle); [scaledTopImg drawInRect:CGRectMake(- scaledTopImg.size.width * 0.5f, -(scaledTopImg.size.height * […]

如何绘制一个三angular形的UIButton

我真的挖了IFTTT右下angular的button,如图(右下)所示。 我尝试过使用CGContext和UIBezierPath来匹配效果,但是我根本不知道如何正确使用它。 有没有人有一些想法/代码如何做到这一点? 谢谢!

CGContext的静态背景

这是我的第一个问题,所以大家好。 我花了一些时间来思考以下问题,不能提出解决scheme。 如果有人能指出我正确的方向,我会很高兴。 我使用CGContext来绘制各种图层的实时数据表示图层,应该以至less50fps的合理帧率刷新。 我想使用静态图像作为背景。 使用每个周期的上下文重新绘制此图像会显着降低帧速率。 我想过使用UIImageView来显示图像一次。 这里的问题是,我想要使用CGContext提供的blendmodes来实现更复杂的覆盖,而不仅仅是为每个图层设置一个alpha值。 由于显示背景图像的UIImageView不是上下文的一部分,因此不受混合模式的影响。 有没有人有一个想法如何实现所需的行为,而不会影响帧率太多? 谢谢你的帮助。

如何使用Core Graphics(用于手指画)创build浮雕效果或阴影效果

我有问题在我的绘图中实现“浮雕/阴影效果”。 手指画图function目前正在我的自定义UIView工作正常,下面是我的drawRect方法代码: 用所有方法编辑代码: – (void)drawRect:(CGRect)rect { CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, self.lineWidth); CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); CGContextSaveGState(context); // for shadow effects CGContextSetShadowWithColor(context, CGSizeMake(0, 2),3, self.lineColor.CGColor); CGContextStrokePath(context); [super drawRect:rect]; } CGPoint midPoint(CGPoint p1, CGPoint p2) { […]

视图的层颜色正在变化时如何使不同的颜色外观

我正在做一些自定义的下载进度栏(分类)的UIButton (或)我也可以在UIView做到这一点,每一件事情都很好,现在我想改变标题的颜色作为收益的进展,例如作为你在下面的图片中可以看到现在我正在得到什么, 我想要的就像下面的图像 我想将标题的颜色更改为白色或其他颜色作为下载进行,有没有什么办法可以做,任何示例代码。 我通过使用下面的代码来实现这一点 – (void)drawInContext:(CGContextRef)progressContext { CGContextSetFillColorWithColor(progressContext, self.progressLayerColor.CGColor); CGMutablePathRef Path = CGPathCreateMutable(); CGRect boundsRect = self.bounds; CGPathMoveToPoint(Path, NULL, boundsRect.origin.x, boundsRect.origin.y); CGPathAddRect(Path, NULL, CGRectMake(0, 0, self.progress, 35)); CGPathCloseSubpath(Path); CGContextAddPath(progressContext, Path); CGContextFillPath(progressContext); CGContextSetBlendMode(progressContext, kCGBlendModeClear); CGContextFillPath(progressContext); CGPathRelease(Path); }

iOS:如何用NSTimer逐步绘制一个圆圈

我想一步一步(如animation计时器)绘制一个没有填充(仅圈的边框)的圆圈。 1旋转等于1天(24小时)。 我真的不知道该怎么做。 我做的步骤 1)我试过https://github.com/danielamitay/DACircularProgress (这是太宽的进展路线) 2)我试图绘制一个有许多弧的圆。 你可以给我一些代码吗? 我真的很困惑。 提前致谢。 编辑 我想使用NSTimer,因为我有一个允许用户停止画圆的button。 如果用户再次触摸一个button – 绘图将不得不继续。

EXC_BAD_ACCES绘制阴影

我想添加一个阴影到我的UIView,但在我的drawRect方法,我得到一个EXC_BAD_ACCESS。 (我正在使用ARC) -(void) drawRect:(CGRect)rect { CGColorRef lightColor = [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor; CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor; CGContextRef context = UIGraphicsGetCurrentContext(); // Draw shadow CGContextSaveGState(context); CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), 10, shadowColor); CGContextSetFillColorWithColor(context, lightColor); CGContextFillRect(context, _coloredBoxRect); CGContextRestoreGState(context); } 错误信息:线程1:编程接收到的信号:“EXC_BAD_ACCESS”。 行: CGContextSetFillColorWithColor(context, lightColor); 当我将这一行更改为: [[UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8] setFill]; 我得到同样的错误,但在这一行: CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), […]

在iOS 7上疯狂的圆angular矩形UIBezierPath行为。什么是交易?

下面的简单的UIView绘制一个圆angular的矩形。 当我通过一个65或以下的angular半径,它正确的轮,但66和以上,它会产生一个完美的圆圈! 这里发生了什么? 当边angular半径等于边框宽度的1/2时,应该只显示一个圆,但不pipe视图的大小是多less,当半径大约是1/3时,似乎都会画一个圆。 这种行为出现在iOS 7上。在iOS 6上,我得到了预期的行为。 #import "ViewController.h" @interface MyView : UIView @end @implementation MyView -(void)drawRect:(CGRect)rect { UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 200, 200) cornerRadius:65]; CGContextRef c = UIGraphicsGetCurrentContext(); CGContextAddPath(c, path.CGPath); [[UIColor redColor] set]; CGContextStrokePath(c); } @end @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; MyView *v = [[MyView alloc] […]

绘制CGContextRef以消除像素化

目前,我正在绘制小点graphics问题。 我注意到,在大多数专业日历应用程序中,事件日历标识是一个小点,其颜色是事件日历颜色。 我目前在我的应用程序点,我需要画一个更好的点。 下面是我的意思的照片。 在这里可能不太明显,但是在我的手机上,这个彩色的点是非常像素的。 我想删除像素化。 我经历了Ray Wenderlich的网站Ray Wenderlich Core Graphics的教程。 下面是我画出来的点子: UIGraphicsBeginImageContext(cell.imageViewPic.bounds.size); CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(contextRef, [[event calendar] CGColor]); CGContextFillEllipseInRect(contextRef,(CGRectMake (0.f, 0.f, cell.imageViewPic.bounds.size.width, cell.imageViewPic.bounds.size.height))); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); cell.imageViewPic.image = image; 所以这实际上是实现了这个圆,但是我加了这个在圆周上划了一条小线来消除像素,但是没有去。 CGPoint startPoint = CGPointMake(cell.imageViewPic.frame.origin.x, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height – 1); CGPoint endPoint = CGPointMake(cell.imageViewPic.frame.origin.x + cell.imageViewPic.frame.size.width – 1, cell.imageViewPic.frame.origin.y + cell.imageViewPic.frame.size.height – […]

CGContext与CALayer

我试图在Quartz 2D上find一个句柄,并在Mac OS X开发人员的在线书籍石英二维graphics 。 一个非常基本的东西,让我困惑的是CGContext。 例如,我可以用下面的代码绘制一个简单的“U”形状,并在CAShapeLayer使用它,而无需引用CGContext 。 CAShapeLayer默认情况下是否隐含/提供了上下文? 我可能在这里混合了几个iOS / OSXgraphicsAPI,所以也许有人可以澄清我的错在哪里。 CGPoint pt1 = CGPointMake(100, 100); CGPoint pt2 = CGPointMake(150, 100); CGPoint pt3 = CGPointMake(150, 200); CGPoint pt4 = CGPointMake(190, 200); CGPoint pt5 = CGPointMake(190, 100); CGPoint pt6 = CGPointMake(210, 100); CGPoint pt7 = CGPointMake(210, 250); CGPoint pt8 = CGPointMake(100, 250); CGPoint pt9 = […]