core-graphics

Can I speed up my use of Core Graphics to draw moving triangles every 1/10th of a second

I have recently added some Core Graphics elements to my app and it has slowed dramatically, rendering it just about useless. I am not sure if I am just not using Core Graphics efficiently (how do I make it faster?) or if this problem is inherent in the use of Core Graphics. My code is below, after this description: There are speech bubb...

How can I draw rotated text without being limited to the MacRoman character set?

Hey folks, My blog has been mentioned here before as an answer to questions. I can't link to one of them, because this form claims I'm a spammer. Sigh. Anyway, now I want to write the definitive blog post on drawing rotated text, so it can also be used for answers here (heh). Here is my first try: http://www.platinumball.net/blog/2009/...

Scaling up iPhone "vector-based graphics" on affine transforms

I made a "Circle" view with this drawRect - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(ctx, color.CGColor); CGContextAddEllipseInRect(ctx, rect); CGContextFillPath(ctx); } When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0), th...

Applying a stroke to a rounded rect in core-graphics

I have a gradient that has rounded corners that I an using for a custom UITableViewCell background. I am trying to apply a stroke to the path but cannot quite do it, and can't see where I am going wrong. CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ; CGFloat miny = CGRectGetMinY(rect) ...

Smoothing a rounded stroke in Core Graphics

I am creating my own UITableViewCells with a gradient background. I have all the logic and drawing worked out, but one thing I want to fix is the "chunkiness" around the corners of my custom cell: If you zoom in on the corners, you can see what I am talking about. Here is the code I a using to generate the cell: CGContextRef c = UI...

How do I draw this exact gradient on the iPhone?

The gradient in question is Figure 8-5 from the Quartz 2D Programming Guide, "A radial gradient that varies between a point and a circle". I'm trying to build a CGGradient object (not a CGShading object, which might be the problem) like so: CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); CGFloat colors[] = { 0,...

Simple menu in iPhone game

I am developing a puzzle game for the iPhone using core graphics implementing drawrect in a single UIView. I would like to add a menu which is opened from a UIButton event handler. I am not sure if I should do this via code e.g. have a menuopen flag and adjust the drawing routines and tap event handlers (manual implementation) or to go...

Problem drawing in custom UIView class

I have a UIView subclass that has the following in drawRect: for(int j=0; j<[myArray count]; j++){ if([myArray objectAtIndex:j]!=@""){ [[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1] set]; CGContextFillRect(context, CGRectMake(55+(20*j),10,15,5)); [[UIColor blackColor] set]; [[myArray objec...

Use a CoreGraphic Stroke as Alpha Mask in iPhone App

Hi All. I'm basically looking to create something akin to a very simple version of iSteam/iFog alebit for a different purpose. In effect there will be two images, one of the subject matter and the other an image of condensation or some such. The user can then wipe their finger over the screen and it will "cut" that from the top layer to ...

Where am I leaking CGMutablePathRef in this code?

In my code I have CGMutablePathRef thePath = CGPathCreateMutable(); If I don't release it I literally get thousands of leaks because I'm doing the action constantly. However, if I do release it, my game eventually crashes. Any ideas? Is it possible I'm releasing it in the wrong place? -(void)MoveObject:(int)Tag { representatio...

NSTrackingArea with fullscreen window/view

I'm trying to install a NSTrackingArea into a fullscreen view in order to get mouse moved events. However, whenever I do, I get an assertion error. I've searched the web, but have not been able to find any leads. *** Assertion failure in -[_NSFullScreenWindow _setTrackingRect:inside:owner:userData:useTrackingNum:install:], /SourceCach...

Is it possible to set the contents of a CALayer from a CGLayer in iPhone SDK?

For a custom UIView I've implemented, I want to display some graphics in multiple CALayers that are added as subviews of my UIViews layer. I cannot use my UIView as the delegate for the sublayers. A UIView may only be the delegate for one layer and that is the layer the UIView already has from the get go. Since I also didn't want to sub...

CAShapeLayer path dissapears after animation - need it to stay in the same place

Thanks to some help on StackOverflow, I am currently animating a path in CAShapeLayer to make a triangle that points from a moving sprite to another moving point on the screen. Once the animation completes, the triangle disappears from the screen. I am using very short durations because this code is being fired every .1 of second for ea...

Multiple Clipped Rects to Create Collage in Core Graphics

I am creating a collage combined with elements from other images. Here is some ASCII art to explain what I am doing: Given images A, B and C, AAA, BBB, CCC AAA, BBB, CCC AAA, BBB, CCC I take part of A, part of B and part of C as columns: Axx, xBx, xxC Axx, xBx, xxC Axx, xBx, xxC ...and combine them in one image like this: ABC ABC A...

Convert 32 bit CGImage to 24 bit?

Trying to convert a 32 bit CGImage to 24 bit and would like to avoid packing it byte-by-byte. Surely there must be a more efficient way ...? Have tried a couple of things like creating a 24 bpp NSBitmapImageRep like this: NSBitmapImageRep* image24 = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:width ...

How to draw polygons with CGPath?

Hello, I have been reading thru the documentation however it is not immediatly clear to me how to draw a polygon using CGPath. All I need to do is to draw CGPath around something like this: __ \ \ \ \ \__\ Could anyone please provide an snippet on how to do this? Additionally I assume CGPathContainsPoint will help me determine...

CGContextSetShadow produces no results

I'm using this code in my UIView subclass to draw a circle with a gradient fill: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadow (context, CGSizeMake(4,4), 5); CGContextBeginPath (context); CGContextAddEllipseInRect(context, CGRectMake(self.bounds.origin.x, self.bo...

iPhone SDK Invert the Colors of a UIImage

Hey everyone I've got an iPhone app that allows a person to draw something on the screen with their finger. They draw with a white line on a black background. However, when I upload this image to the web server, the line itself is white. I have been trying to work through the core graphics libraries in search of a way to invert the colo...

Saving CoreGraphics drawing actions?

Is there some way I can do something like: @implementation MyView - (void)drawRect:(CGRect)rect { // Get the thing I'm supposed to draw (CGImageRef, pattern, etc.) and draw it // i.e. not real code CGContextDrawWhatever(self.objectThatHoldsDrawing.drawing); } ...

How do I add an outer glow to a UIImage or UIImageView or UIView

I want to add a FADED shadow/outer glow to a UIImage/UIImageView/UIView but I know no Core Graphics at all. Edit: Please Help!! ...