core-graphics

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,

Draw a shadow which is hidden under the semi-transparent view?

好久不见. 提交于 2019-12-04 15:15:01
I have a semi-transparent view with a drop shadow. I mocked it up in photoshop, which doesn't draw the shadow under the object. Then I made it in xcode, but it obviously does draw the shadow underneath. I was wondering if there's a way to avoid this. In other words - have the shadow only appear outside of the shape? You probably want to set the rasterized property of the layer to YES, which will composite the shadow before other effects such as opacity are applied to the view. Note however that this has a big performance impact. There's a handy table of different shadow implementations and

Draw partial image or clipping diagonally using Core Graphics

≡放荡痞女 提交于 2019-12-04 15:01:41
I am looking to draw an image using Core Graphics.However I am able to draw the partial image i.e Horizontally & vertically. But instead of it I want to have it in a Diagonal Way.For more clarification, pls refer to below image : Real Image : Required Image Output: Below is the code using to fill the Layer with Color : CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(contextRef, r.origin.x, r.origin.y ); CGContextAddLineToPoint(contextRef, r.origin.x , r.origin.y); CGContextAddLineToPoint(contextRef, r.origin.x + (r.size.width ), r.origin.y + (r.size.height));

CoreGraphics: Using finger strokes to erase part of image?

倖福魔咒の 提交于 2019-12-04 14:55:45
I'm working on drawing code to erase part of an image. I'm not an expert on CoreGraphics and could use some help. This routine works fine, however, when moving fast, it loses touches (Not very smooth). Can this routine be modified to make CGContextClearRect smoother? Is there a better, faster way to do this? -(void)drawRect:(CGRect)rect { if (!myDrawing) { // touchpoints stored here myDrawing = [[NSMutableArray alloc] initWithCapacity:0]; } UIGraphicsBeginImageContext(frontImage.frame.size); [frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height

Draw an image in Additive Blend Mode without using OpenGL

蓝咒 提交于 2019-12-04 14:47:17
I want to draw an image using an additive blend mode. But I don't want to use OpenGL. I can't find anything to do this, maybe there's something in Quartz2D? Can anyone point me in the right direction? Cheers, Rich Krzysztof Zabłocki Sure there is enum CGBlendMode which you can use to specify blending operation. use method: CGContextSetBlendMode() or [image drawInRect:CGRectMake(0, 0, width, height) blendMode:mode alpha:1]; more at developer site: link text 来源: https://stackoverflow.com/questions/3908160/draw-an-image-in-additive-blend-mode-without-using-opengl

How to create a perfect half circle with CGPathAddCurveToPoint?

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:35:47
I am trying to create a perfect right half circle of 15 points radius with CGPathAddCurveToPoint, like this: CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30); It starts at the top middle of the circle. Then the first control point is set to the top right corner of the circle's bounding box. The second control point is set to the bottom right corner of the circle's bounding box. The circle ends at bottom middle of the bounding box. But when drawn, the circle has an egg-like shape. How can I make a perfect, flawless right semisphere starting at point 0

Converting BGRA to ARGB

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:31:21
问题 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? 回答1: 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

Programmatically change resolution OS X

五迷三道 提交于 2019-12-04 14:17:03
问题 My question is simple. I am developing a game and, as the title states, I want to be able to programmatically change the display resolution / refresh rate on OS X. I've been searching for this for hours and couldn't find anything. I already know how to create a full screen window. I would also want to get the list of supported resolutions and refresh rates 回答1: From Apple's OpenGL Programming Guide for Mac OS X: Drawing to the Full Screen: Avoid changing the display resolution from that

UIBezierPath not drawing a smooth curve

早过忘川 提交于 2019-12-04 14:14:59
问题 I am using UIBezierPath for drawing, and I have written the code on touch events and its working fine, but my curves are not smooth, when I am move my finger around and draw some curve, they are not smooth. - (void)drawRect:(CGRect)rect { [[UIColor redColor] setStroke]; for (UIBezierPath *_path in pathArray) [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; } #pragma mark - Touch Methods -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { myPath=[[UIBezierPath alloc]init

Add an annotation on a pdf

空扰寡人 提交于 2019-12-04 14:07:11
问题 I have to develop a iPad app which can view a PDF file and draw some predefined annotations on it dynamically. It's like http://plangrid.com/ do. I went though WWDC videos, stackoverflow and some other blogs. But could not find a way to add a controller bar on the PDF. And drag a annotation from it and drop on the PDF. I have an idea about to view a PDF. I followed ZoomingPDFViewer example. Please advise me. I'm using XCode 4 and iOS 4.3. 回答1: I'm not sure if you found the following