core-graphics

how to create a path using coregraphics?

给你一囗甜甜゛ 提交于 2019-12-03 10:06:34
i want to create a path.something like i touch the screen and draw line in touchmove event.when line intersect from starting point.fill that path using any colour. now see in the image i've drawn a line.i just want to detect if line intersects again to start point.then fill that path with my own desired color.also i m using core graphics to draw line but it's very slow on real device.could you tell me a way to improve speed? Header: #import <UIKit/UIKit.h> @interface myView : UIView { CGMutablePathRef path; CGPathRef drawingPath; CGRect start; BOOL outsideStart; } @end Implementation: #import

CALayer: Single pixel line looks like 2 pixels

∥☆過路亽.° 提交于 2019-12-03 09:57:13
问题 This is my code: int columns 3; int columnWidth = self.layer.bounds.size.width / 3; for (int c = 1; c < columns; c++) { CALayer *layer = [CALayer layer]; layer.frame = (CGRectMake(columnWidth * c + 0.5, 0.5, 1, self.layer.bounds.size.height)); layer.backgroundColor = myColor; [grid addSublayer:layer]; } I understand that I have to shift the x and y 0.5 pixels, which is what I have done, yet it still shows as a 2 pixel line instead of 1. 回答1: Set the layer Frame as layer.frame = (CGRectMake

Turn two CGPoints into a CGRect

▼魔方 西西 提交于 2019-12-03 09:20:40
问题 How can I, given two different CGPoints , turn them into an CGRect ? Example: CGPoint p1 = CGPointMake(0,10); CGPoint p2 = CGPointMake(10,0); How can I turn this into a CGRect ? 回答1: This will take two arbitrary points and give you the CGRect that has them as opposite corners. CGRect r = CGRectMake(MIN(p1.x, p2.x), MIN(p1.y, p2.y), fabs(p1.x - p2.x), fabs(p1.y - p2.y)); The smaller x value paired with the smaller y value will always be the origin of the rect (first two arguments). The

How to create UIBezierPath gradient fill?

╄→гoц情女王★ 提交于 2019-12-03 09:19:59
I would like to create a UIBezierPath with 10px rounded corners and with gradient fill. How can I acheive this effect? Here's an image of what I want to do: As you can see, this square has: 2px black border 10px rounded corners red to green linear gradient fill How can I do this programatically without using pattern image color ? Here's how I create the path: UIBezierPath *border = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10.0f]; [border setLineWidth:2]; [[UIColor blackColor] setStroke]; [border stroke]; [[UIColor redColor] setFill]; <-- what should I put here? [border

iOS: CGAffineTransformScale moves my object

会有一股神秘感。 提交于 2019-12-03 09:13:16
问题 Building on a question I had earlier. Simple button trying to transform a label. I want it to shrink by 0.5, which works but for some reason it also moves the object as it does it. The label jumps up and to the left, then transforms. - (IBAction)btnTest:(id)sender { [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ lblTest.transform = CGAffineTransformScale(lblTest.transform, 0.5f,0.5f); }completion:^(BOOL finished) { if(finished){ NSLog(@"DONE");

iphone: Apply a texture to CGContextStrokePath

烈酒焚心 提交于 2019-12-03 08:56:08
I search all the question and answer in StackOverflow but can not get the result I want. I would like to use a PNG file, to display as a stroke at the point user touch and move. This is the PNG file: But I did all the ways on StackOverflow, even using CGPatternRef, but I don't have the result I want. The result I have is here: But the result I want to have is here: This result I have done in OpenGL ES, but I can not do that in Core Graphics. I think I can use CGContextDrawImage at each point, but this way cause poor performance because I must draw image all the points between 2 points user

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

Doing completely custom animations with Core Animation - performance

*爱你&永不变心* 提交于 2019-12-03 08:43:52
The article https://www.objc.io/issues/12-animations/animating-custom-layer-properties/ has this to say about doing completely custom animations with Core Animation: Suppose that instead of implementing our clock face using individual layers, we wanted to draw the clock using Core Graphics. (In general this will have inferior performance , but it’s possible to imagine that there are complex drawing operations that we might want to implement that would be hard to replicate using ordinary layer properties and transforms.) How would we do that? In other words, we draw each frame of the CA

Converting BGRA to ARGB

纵饮孤独 提交于 2019-12-03 08:35:49
I'm reading this tutorial on getting pixel data from the iPhone camera. While I have no issue running and using this code, I need to take the output of the camera data (which comes in BGRA) and convert it to ARGB so that I can use it with an external library. How do I do this? If you're on iOS 5.0, you can use vImage within the Accelerate framework to do a NEON-optimized color component swap using code like the following (drawn from Apple's WebCore source code ): vImage_Buffer src; src.height = height; src.width = width; src.rowBytes = srcBytesPerRow; src.data = srcRows; vImage_Buffer dest;

Rotate UIImageView clockwise

吃可爱长大的小学妹 提交于 2019-12-03 08:29:49
问题 This should be simple, but I'm having trouble rotating a UIImageView a full 360 degrees, repeated forever. [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{ self.reloadButton.imageView.transform = CGAffineTransformRotate(self.reloadButton.imageView.transform, -M_PI); } completion:^(BOOL finished) { }]; According to the docs, the