core-graphics

Draw a perfect circle from user's touch

血红的双手。 提交于 2019-12-02 13:47:17
I have this practice project that allows the user to draw on the screen as they touch with their fingers. Very simple App I did as exercise way back. My little cousin took the liberty of drawing things with his finger with my iPad on this App (Kids drawings: circle, lines, etc, whatever came to his mind). Then he started to draw circles and then he asked me to make it "good circle" (from my understanding: make the drawn circle perfectly round, as we know no matter how stable we try to draw something with our finger on the screen, a circle is never really as rounded like a circle should be). So

Eraser the drawing in iOS

柔情痞子 提交于 2019-12-02 11:43:11
I am working on a drawing app, I have a UIBezeirPath, with which I draw in touchesMoved, and convert it to CGPath and then draw on to CGlayer, Here is my code -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { self.currentPath = [[DrawingPath alloc] init]; if(m_eraseButtonClicked) { [self.currentPath setPathColor:[UIColor backgroundColor]]; } else { [self.currentPath setPathColor:self.lineColor]; } CGPathRef cgPath = self.currentPath.path.CGPath; mutablePath = CGPathCreateMutableCopy(cgPath); } - (void)Erase { CGContextRef layerContext = CGLayerGetContext(self.DrawingLayer);

Memory management in Coregraphics (iOS)

我怕爱的太早我们不能终老 提交于 2019-12-02 11:04:45
问题 I am working on a drawing application, I am using CGlayers for drawing, So I open my canvas for drawing on click of a button, I am using UIBezierPath and then converting it to CGPath in touchesMoved below and then using it to draw -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self

Changing color space on and image

两盒软妹~` 提交于 2019-12-02 10:02:34
I'm creating a mask based on DeviceGray color space based image. What basically I want to do is to change all sorts of gray (beside black) pixels into white and leave black pixels as they are. So I want my image to be consisted with black and white pixels. Any idea how to achieve that using CoreGraphics means ? Please dont offer running all over the pixels in the loop Use CGImageCreateWithMaskingColors and CGContextSetRGBFillColor together like this: CGImageRef myMaskedImage; const CGFloat myMaskingColors[6] = { 0, 124, 0, 68, 0, 0 }; myColorMaskedImage = CGImageCreateWithMaskingColors (image,

CAGradientLayer bounds not changing

匆匆过客 提交于 2019-12-02 09:41:17
I have a CAGradientLayer which is added to a UIVIew , when I rotate the device the view that it is added to increases in size (with autolayout) however the CA layer doesn't change its size. I have tried implementing the viewDidLayoutSubviews method and setting the layers frame in there but it doesn't make any difference. Once the device is rotated if I navigate away from the view and then back to it then the layer gets drawn correctly. You could override - (void)layoutSubviews in your UIView subclass and then update the layers frame. 来源: https://stackoverflow.com/questions/33414131

How do I check if CGContext contains point?

和自甴很熟 提交于 2019-12-02 09:22:38
Basically I have image that gets drawn when the touch is moved. When i toggle on a button called eraser I want it to detect if the context I have drawn is NOT black at the position the touch is at. Is there any way to do this? - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { hue = 0.0; [self initContext:frame.size]; framsize = frame.size; } return self; } -(void)clear{ cacheContext = nil; cacheBitmap = nil; [self initContext:framsize]; [self setNeedsDisplay]; } - (BOOL) initContext:(CGSize)size { float scaleFactor = [[UIScreen mainScreen] scale]; int

How to color manage AVAssetWriter output

假如想象 提交于 2019-12-02 08:59:28
问题 I'm having trouble getting a rendered video's colors to match the source content's colors. I'm rendering images into a CGContext, converting the backing data into a CVPixelBuffer and appending that as a frame to an AVAssetWriterInputPixelBufferAdaptor. This causes slight color differences between the images that I'm drawing into the CGContext and the resulting video file. It seems like there are 3 things that need to be addressed: tell AVFoundation what colorspace the video is in. make the

CGLayerRef in NSValue - when to call retain() or release()?

混江龙づ霸主 提交于 2019-12-02 08:25:58
I am caching some graphics onto CGLayers and then storing them in NSValue objects using @encode (so as to store them in an array). I just wanted to make sure that I handle the retain/release correctly... I cache the graphics and store them in the array something like this: // Create an NSMutableArray "newCache" CGLayerRef drawingLayer = CGLayerCreateWithContext(context, bounds.size, NULL); CGContextRef drawingContext = CGLayerGetContext(drawingLayer); // Do some drawing... [newCache addObject:[NSValue valueWithBytes:&drawingLayer objCType:@encode(CGLayerRef)]]; CGLayerRelease(drawingLayer); //

UIColor SetFill doesn't work

匆匆过客 提交于 2019-12-02 07:30:28
问题 In this code for (int i=0;i<3;i++) { CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10); CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*(i+1), self.yShift+self.rectLen*10+self.rectLen); CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width+self.rectLen*i, self.yShift+self.rectLen*10+self.rectLen); CGContextAddLineToPoint(context, self.xShift+15+self.rectLen*self.width

Problem with CGImageDestination and file naming

落爺英雄遲暮 提交于 2019-12-02 06:53:22
I am capturing images from the camera, using AVCapture as I have need of speed and the standard kit stuff is way too slow. I have problem whereby the file that is being output (an animated GIF) is having it's file name mangles by the CGImageDestination functions... When I output the NSURL (cast to a CFURLRef) to the log I get the path/filename I intended: 2011-09-04 20:40:25.914 Mover[3558:707] Path as string:.../Documents/91B2C5E8-F925-47F3-B539-15185F640828-3558-000003327A227485.gif However, once the file is created and saved it actually lists the filename as this: 2011-09-04 20:40:25.960