cgcontext

Extra line when drawing an arc in swift

喜夏-厌秋 提交于 2019-12-04 22:00:52
I have this kind of code in a swift app and I get an extra greyed line reaching the starting point of the arc. The arc itself is drawn as expected, but it seems like CGContextMoveToPoint is leaving some trace behind before reaching the starting point. override func drawRect(rect: CGRect) { var context:CGContextRef = UIGraphicsGetCurrentContext(); var centerX,centerY,startAngle,endAngle,radius:CGFloat startAngle = CGFloat(M_PI_4) endAngle = -startAngle radius = (rect.height/2) / sin(startAngle) centerX = rect.width/2 + (radius*cos(startAngle)) centerY = rect.height/2 CGContextMoveToPoint

Memory consumption spikes when resizing, rotating and cropping images on iPhone

[亡魂溺海] 提交于 2019-12-04 20:27:12
I have an "ImageManipulator" class that performs some cropping, resizing and rotating of camera images on the iPhone. At the moment, everything works as expected but I keep getting a few huge spikes in memory consumption which occasionally cause the app to crash. I have managed to isolate the problem to a part of the code where I check for the current image orientation property and rotate it accordingly to UIImageOrientationUp . I then get the image from the bitmap context and save it to disk. This is currently what I am doing: CGAffineTransform transform = CGAffineTransformIdentity; // Check

How to make the different colour appearance while layer color of the view is changing

冷暖自知 提交于 2019-12-04 20:02:47
I am doing some custom download progresses bar in side the (subclassed) UIButton (or) i can also do that in UIView , every thing is fine, now i want change the colour of the title as the progress the proceeds, for example as u can see in the below image shows what is now i am getting, what i want is like below image i want change the color of the title to white or some other color as download proceeds, is there any way i can do, any sample code for this. i am achieving this by using below code - (void)drawInContext:(CGContextRef)progressContext { CGContextSetFillColorWithColor(progressContext,

Position a View for drawing via renderInContext:

我与影子孤独终老i 提交于 2019-12-04 15:32:05
问题 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,

How to erase part of an image as the user touches it

泪湿孤枕 提交于 2019-12-04 10:20:28
My big picture goal is to have a grey field over an image, and then as the user rubs on that grey field, it reveals the image underneath. Basically like a lottery scratcher card. I've done a bunch of searching through the docs, as well as this site, but can't find the solution. The following is just a proof of concept to test "erasing" an image based on where the user touches, but it isn't working. :( I have a UIView that detects touches, then sends the coords of the move to the UIViewController that clips the image in a UIImageView by doing the following: - (void) moveDetectedFrom:(CGPoint)

What this error is invalid context 0x0?

浪尽此生 提交于 2019-12-04 09:29:29
I wrote the following code in ViewDidLoad // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void)viewDidLoad { [super viewDidLoad]; NSString *str = [NSString stringWithFormat:@"Veer"]; CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); CGFloat values[4] = {55.0, 0.0, 0.0, 1.0}; CGColorRef glowColor = CGColorCreate(rgbColorspace, values); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor( context, CGSizeMake( 5.0, 0.0 ), 20.0f, glowColor); [str drawAtPoint:CGPointMake(10.5f, 0.5f) withFont:[UIFont

Invalid context when creating UIImageView

蹲街弑〆低调 提交于 2019-12-04 09:19:23
问题 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

Masking an image using bezierpath with image's full resolution

。_饼干妹妹 提交于 2019-12-04 05:10:49
问题 Hi, I have a path (shape) and a high-resolution image. I make the high res image to be AspectFit inside the view on which I draw the path and I want to mask the image with the path but at the full resolution of the image, not at the resolution in which we see the path. The problem, It works perfectly when I don't upscale them up for high-resolution masking but when I do, everything is messed up. The mask gets stretched and the origins don't make sense. All I want is to be able to upscale the

How to get rid of this “points” between my lines when I am drawing?

天涯浪子 提交于 2019-12-04 05:09:53
is there an easy way to not draw this points in my lines? I don't know why this points are there because i never release my finger from screen during drawing of a line. I got the code from a drawing example. // draw a line - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; currentPoint.y -= 0; // 20 only for 'kCGLineCapRound' UIGraphicsBeginImageContext(self.view.frame.size); //Albert Renshaw - Apps4Life [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame

Using NSString's drawAtPoint method in place of CGContextShowGlyphsAtPoint problems

别来无恙 提交于 2019-12-04 03:14:28
In my app I'm trying to render text along a path; this is fine for most characters but not for Japanese (or anything non mac-Roman). I've been advised to use [NSString drawAtPoint] which displays the correct characters in my CATiledLayer; however, they dissapear after approximately 5 seconds. In this time I can zoom the layer and they scale properly, but they don't seem to get committed to the CATiledLayer like the rest of the text usually is. Before I render, I check the string and decide whether any of them will not be renderable. If I'm going to have issues, I use drawAtpoint instead: if (