core-graphics

Adding glowing effect to the circle

时间秒杀一切 提交于 2019-12-06 04:34:21
问题 I draw a circle in the drawRect method and fill it with a color. Now i need to add a glowing effect to the circle. When i click on a button, the circle needs to glow. How can i do this? Any help will be greatly appreciated! Thanks in advance!!! 回答1: If you are using Quartz 2D, you can simply add a white shadow to the circle. See the Quartz 2D Programming Guide for Shadows Apple's Sample code for setting up a shadow taken from the link above: void MyDrawWithShadows (CGContextRef myContext, //

ios: how to blur a image with CGPath?

孤街浪徒 提交于 2019-12-06 04:03:23
问题 I create a CGPath area as shown green circle. The CGPath area need to be clear, and the rest of image will be applied blurry or translucent effect, I can clip image inside CGPath with following code: UIGraphicsBeginImageContext(view.frame.size); CGContextAddPath(ctx, path); CGContextClip(ctx); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(clipImage, nil,

How can I fill a rect with an alpha color using CoreGraphics?

穿精又带淫゛_ 提交于 2019-12-06 03:49:52
问题 In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this: [[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); The problem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks in advance! 回答1: Use CGContextSetBlendMode() before you draw the rect. 回答2: Set your view background color to transparent… It should work. 来源: https:/

iOS: How to create and draw into (and save) an image larger than the screen?

隐身守侯 提交于 2019-12-06 03:41:25
We're creating an iOS photo app. In doing this, we have to create dynamically sized images up to about 2500x1600px. Once this image has been created, we want to draw smaller images on top of the big one reasonably quickly. The problem as we can see it is that it's impossible to get a context larger than the screen resolution. The call does not crash, but it returns a nil-context. How can such a seemingly simple task be achieved? Secondly, once this context is created, what is the fastest way to draw a small image at a given position on top of the big one? Edit: We found the solution.

Draw Triangle iOS

老子叫甜甜 提交于 2019-12-06 03:36:04
问题 The code below is drawing me a circle, how can I modify the existing code to draw a triangle instead? _colorDotLayer = [CALayer layer]; CGFloat width = self.bounds.size.width-6; _colorDotLayer.bounds = CGRectMake(0, 0, width, width); _colorDotLayer.allowsGroupOpacity = YES; _colorDotLayer.backgroundColor = self.annotationColor.CGColor; _colorDotLayer.cornerRadius = width/2; _colorDotLayer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 回答1: While there are shown

draw a straight line in swift 3 and core graphics

*爱你&永不变心* 提交于 2019-12-06 03:34:16
I'm trying to draw a single, straight line using core graphics and swift 3 However, when touchesmoved is called, it creates multiple lines instead of just a single line. Code used is below: import UIKit class ViewController: UIViewController { @IBOutlet weak var drawingPlace: UIImageView! var startTouch : CGPoint? var secondTouch : CGPoint? override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = touches.first startTouch = touch?.location(in: drawingPlace) } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches{

How to store an OpenGL program object's uniforms per-context instead of per-program?

我们两清 提交于 2019-12-06 02:59:17
I'm working on a multithreaded OpenGL compositing engine. I have a set of shaders which I'm sharing among multiple contexts. For performance reasons, I'd like to avoid compiling a separate instance of each shader program for each thread. But, if multiple threads happen to use the same program object and I try to set different uniforms on each thread, the uniform values get mixed up since uniform values are stored with the shared program object. So far I see my options as: compile a separate program object for each thread (which wastes time and resources), or for each shared program object,

How can I read-modify-write a PDF (CGPDFDocument) on iOS?

馋奶兔 提交于 2019-12-06 02:57:53
I am trying to modify the PDF metadata (title, author, etc.) of an existing PDF on iOS. While it is easy to find sample code for PDF parsing and for PDF creation from scratch, there does not seem to be an easy way to dump an existing PDF into a new file - and modify it just slightly. More specifically, how do I get the info obtained when reading a PDF roughly like this: CGPDFDocumentRef myPDF = CGPDFDocumentCreateWithURL((CFURLRef)urlOfInputPDF); CGPDFDictionaryRef myPDFDict=CGPDFDocumentGetInfo(myPDF); into the new PDF, which I would create roughly this way: CGRect pageRect;

Crop image in star shape iphone

本秂侑毒 提交于 2019-12-06 02:42:20
I have a image in rectangle shape but i want to crop this image in a star shape in my iphone application. so please can any one suggest how i do this? plz suggest. thanks DarkDust See the comment to a related question on how to mask an image. The magical part is CGContextClipToMask . 来源: https://stackoverflow.com/questions/5701152/crop-image-in-star-shape-iphone

Clearing CGPath path after drawing is done

烈酒焚心 提交于 2019-12-06 02:24:53
I've written a program for drawing in iOS in touchesMoved() method. CGContextAddPath(UIGraphicsGetCurrentContext(), path); CGPathMoveToPoint(path, NULL, lastPoint.x, lastPoint.y); CGPathAddLineToPoint(path, NULL, lastPoint.x, lastPoint.y); CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathStroke); How can i clear the path drawn and restore the original view? Perhaps you can put an invisible view above your view of drawing and add the path traced by the user only when u are sure that the user will not undo. If the user wants the undo action, don't add the path to the context. Thats my