cgcontext

iOS: Improving speed of image drawing

China☆狼群 提交于 2019-12-03 10:14:20
问题 I have a sequence of images that I want to animate ( UIImageView supports some basic animation but it's not sufficient for my needs). My first approach was to use UIImageView and set the image property when the image. This was too slow. The reason for the poor speed was due to the drawing of the images (which surprised me; I assumed the bottle neck would be loading the image). My second approach was to use a generic UIView and set view.layer.contents = image.CGImage . This gave no noticeable

Drawing Hollow circle in iPhone

痴心易碎 提交于 2019-12-03 09:19:46
问题 i need to draw the following image The Gray part is what i want to draw over another image what is the Code i need to use using CGContext methods, i tried using the CGContextAddArc but failed because when i fill the stroke the center hollow is also filled with the grey texture. Any help appreciated. Info : I have the Complete Blue Image , i need to add the Semi Circle above the blue image Thanks 回答1: Have a look at Filling a Path in the Core Graphics documentation. Basically, what you do is

Swift - Using CGContext to draw with finger

流过昼夜 提交于 2019-12-03 09:13:37
I'm trying to make a drawing app. I have a single custom UIView: class DrawView: UIView { var touch : UITouch! var lastPoint : CGPoint! var currentPoint : CGPoint! override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { touch = touches.first as! UITouch lastPoint = touch.locationInView(self) println(lastPoint) } override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { touch = touches.first as! UITouch currentPoint = touch.locationInView(self) self.setNeedsDisplay() lastPoint = currentPoint } override func drawRect(rect: CGRect) { var context =

Position a View for drawing via renderInContext:

旧街凉风 提交于 2019-12-03 08:55:46
I want to draw a UIView in my current CGGraphicsContext . I draw the UIView via renderInContext: , but it's not positioned correctly (always in the top left corner). I have all values of the UIView available for drawing the UIView . CGRect frame; CGRect bound; CGPoint center; CGAffineTransform transform; I currently set the position and rotation of the layer like this: CGContextTranslateCTM(context, frame.origin.x, frame.origin.y); CGContextRotateCTM(context, (CGFloat) atan2(transform.b, transform.a)); But the position is, due to the rotation, not correct and differs from the original position

iphone MPMoviePlayerViewController CGContext Errors

耗尽温柔 提交于 2019-12-03 07:22:36
I am writing an app for the iPhone that will play some movies utilizing MPMoviePlayerViewController . So far I have gotten it to play movies, however it is throwing some errors in the debugger that all start with CGContext . I have wracked my brain in trying to fix it. Here are the details of my code: .h file: #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> @interface MovieViewController : UIViewController { MPMoviePlayerViewController *playerController; } -(IBAction) playMovie:(id)sender; .m file: @interface MovieViewController () @end @implementation -(IBAction)playMovie:(id

CGContext: how do I erase pixels (e.g. kCGBlendModeClear) outside of a bitmap context?

我怕爱的太早我们不能终老 提交于 2019-12-03 07:01:18
问题 I'm trying to build an eraser tool using Core Graphics, and I'm finding it incredibly difficult to make a performant eraser - it all comes down to: CGContextSetBlendMode(context, kCGBlendModeClear) If you google around for how to "erase" with Core Graphics, almost every answer comes back with that snippet. The problem is it only (apparently) works in a bitmap context. If you're trying to implement interactive erasing, I don't see how kCGBlendModeClear helps you - as far as I can tell, you're

Drawing triangle/arrow on a line with CGContext

一笑奈何 提交于 2019-12-03 05:15:51
问题 I am using the framework of route-me for working with locations. In this code the path between two markers(points) will be drawn as a line. My Question: "What code should I add if I want to add an arrow in the middle(or top) of the line, so that it points the direction" Thanks - (void)drawInContext:(CGContextRef)theContext { renderedScale = [contents metersPerPixel]; float scale = 1.0f / [contents metersPerPixel]; float scaledLineWidth = lineWidth; if(!scaleLineWidth) { scaledLineWidth *=

How to procedurally draw rectangle / lines in swift using CGContext

為{幸葍}努か 提交于 2019-12-03 03:51:36
问题 I've been trawling the internet for days trying to find the simplest code examples on how to draw a rectangle or lines procedurally in Swift. I have seen how to do it by overriding the DrawRect command. I believe you can create a CGContext and then drawing into an image, but I'd love to see some simple code examples. Or is this a terrible approach? Thanks. class MenuController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the

Invalid context when creating UIImageView

吃可爱长大的小学妹 提交于 2019-12-03 02:40:43
I have an error when I tried to create a UIImageView. Look at this code : UIImage* backgroundPanel = [[UIImage imageNamed:@"loginPanelBackground.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(90, 0, 149, 416)]; self.connexionBackgroundImgView = [[UIImageView alloc] initWithImage:backgroundPanel]; self.connexionBackgroundImgView.frame = CGRectMake(0, 0, 416, 390); // THIS LINE PROVOC THE INVALID CONTEXT [self.connexionView insertSubview:self.connexionBackgroundImgView aboveSubview:self.connexionToCreationCompteView]; It throws this error in the log : <Error>: CGContextSaveGState: invalid

iPhone CGContext: drawing two lines with two different colors

余生长醉 提交于 2019-12-03 02:35:41
I am having some troubles using the CGContext with an iPhone app. I am trying to draw several lines with different colors, but all the lines always end up having the color which was used last. I tried several approaches, but haven't been lucky. I set up a small sample project to deal with that issue. This is my code, I use in the drawRect method. I am trying to draw a red and a blue line: - (void)drawRect:(CGRect)rect{ NSLog(@"drawrect!"); CGContextRef bluecontext = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(bluecontext, 2.0); CGContextSetStrokeColorWithColor(bluecontext, [UIColor