cgcontextref

How to clear circle in CGContext in iOS

倾然丶 夕夏残阳落幕 提交于 2020-05-26 09:09:51
问题 I want create image using CGcontext. This is simple image with white or black background. also I want to add transperent part which is in circle ( check attached image). I know how to do this in rect. But i want to make it circle. Please anyone help me in this. 回答1: Use the below code to clear circle in your context -(UIImage *) getImageWithcenterClear:(CGPoint) center{ CGRect frame = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContextWithOptions([[UIScreen mainScreen] bounds].size,

How to clear circle in CGContext in iOS

坚强是说给别人听的谎言 提交于 2020-05-26 09:09:21
问题 I want create image using CGcontext. This is simple image with white or black background. also I want to add transperent part which is in circle ( check attached image). I know how to do this in rect. But i want to make it circle. Please anyone help me in this. 回答1: Use the below code to clear circle in your context -(UIImage *) getImageWithcenterClear:(CGPoint) center{ CGRect frame = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContextWithOptions([[UIScreen mainScreen] bounds].size,

How save CGContextRef as .PNG file?

ぐ巨炮叔叔 提交于 2020-01-05 08:50:13
问题 I create a drawing iOS application in which I would like to create a "Save Image" method. The drawing takes place inside the touchesMoved: method. - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; [self drawToCache:touch]; [self setNeedsDisplay]; } - (void) drawToCache:(UITouch*)touch { hue += 0.005; if(hue > 1.0) hue = 0.0; UIColor *color = [UIColor colorWithHue:hue saturation:0.7 brightness:1.0 alpha:1.0];

Can I draw shapes like circle,rectangle,line etc outside drawRect method

北慕城南 提交于 2019-12-22 09:05:33
问题 Can I draw shapes like circle, rectangle, line etc outside drawRect method using CGContextRef contextRef = UIGraphicsGetCurrentContext(); or is it mandatory to use it inside drawRect only. Please help me, let me know how can I draw shapes outside drawRect method. Actually i want to go on plotting dots on touchesMoved event. This is my code for drawing a dot. CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(contextRef, 0, 255, 0, 1); CGContextFillEllipseInRect

iOS之CoreGraphics使用(1)

荒凉一梦 提交于 2019-12-07 11:18:08
CoreGraphics.framework 是iOS 内置的用于画图的框架,可以画自定义的几何图形,它支持图形上下文、加载图像、绘制图像,等等。 下面是我今天练习的代码: (1)代码1:绘制字符串 - (void)drawRect:(CGRect)rect { // Drawing code UIColor * magentaColor = [UIColor colorWithRed:0.5f green:0.0f blue:0.5f alpha:1.0f]; [magentaColor set]; UIFont * helveticaBold = [UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0f]; NSString * myString = @"I Learn Really Fast"; [myString drawAtPoint:CGPointMake(25, 190) withFont:helveticaBold]; } (2)代码2:绘制图像 -(void)drawRect:(CGRect)rect { UIImage * image = [UIImage imageNamed:@"xcode.png"]; if(image != nil) { NSLog(@"Successfully loaded the

How to create embossed or shadow effects using Core Graphics (for finger paint)

北战南征 提交于 2019-12-07 05:09:41
问题 I have issue to implement "Emboss/Shadow effects" in my drawing. Finger paint functionality is currently working fine with my custom UIView and below is my drawRect method code: Edit code with all methods : - (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);

iOS开发CoreGraphics核心图形框架之二——深入理解图形上下文

限于喜欢 提交于 2019-12-06 19:31:53
iOS开发CoreGraphics核心图形框架之二——深入理解图形上下文 一、引言 在上一篇博客中,介绍了有关CGPath绘制路径的相关方法,其中在View视图的drawRect方法中,已经使用过上下文将Path路径绘制到当前视图上,上一篇博客只是抛砖引玉,本片博客将更深入的介绍下有关上下文的更多内容。关于接胡搜啊CGPath应用的博客地址如下: iOS开发CoreGraphics核心图形框架之一——CGPath的应用: https://my.oschina.net/u/2340880/blog/757072 。 二、关于图形上下文Graphics Context GraphicsContext对于开发者来说是完全透明的,开发者不需要关心其实现,也不需要关心其绘制方式,开发者只需要将要绘制的内容传递给图形上下文,由图形上下文来将内容绘制到对应的目标上。这个目标可以是视图,窗口,打印机,PDF文档或者位图对象。需要注意,绘制的顺序在CoreGraphics框架中十分重要,如果后绘制的内容和先绘制的内容有位置冲突,后绘制的内容将覆盖先绘制的内容。 特定的上下文用于将内容绘制到特定的输出源上,CoreGraphics中提供如下几种图形上下文: 1.位图图形上下文:位图图形上下文用于将RGB图像,GMYK图像或者黑白图像绘制到一个位图(bitmap)对象中。 2.PDF图形上下文

How to create embossed or shadow effects using Core Graphics (for finger paint)

筅森魡賤 提交于 2019-12-05 11:42:53
I have issue to implement "Emboss/Shadow effects" in my drawing. Finger paint functionality is currently working fine with my custom UIView and below is my drawRect method code: Edit code with all methods : - (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

How to erase finger paint on Custom UIView in iPhone

走远了吗. 提交于 2019-12-03 22:32:58
问题 I have created a custom UIView (without .xib) for a finger paint application. Paint is working fine with custom UIView but my problem is that when I try to erase the painted path I am getting: Error : Invalid context Below is my class: .h file @interface draw2D : UIView { CGPoint previousPoint; CGPoint lastPoint; CGMutablePathRef path; UIButton *btnClose; UIButton *btnErase; BOOL IsErase; } - (IBAction)btnClose:(id)sender; - (IBAction)btnErase:(id)sender; @end @implementation draw2D - (void

Do you need to release CGContextRef in Swift?

回眸只為那壹抹淺笑 提交于 2019-12-03 19:23:01
问题 I've created a context using CGBitmapContextCreate. Do I need to release it using CGContextRelease? I know the answer is yes in Objective-C, but how about in Swift? Thanks! 回答1: CFTypes are automatically managed unless explicitly specified as Unmanaged. According to the documentation. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html Core Foundation objects returned from annotated APIs are automatically memory managed in