core-graphics

CGPathAddArc vs CGPathAddArcToPoint

Apple's CoreGraphics library defines two functions for describing an arc. CGPathAddArc adds an arc based on a center point, radius, and pair of angles. CGPathAddArcToPoint adds an arc based on a radius and a pair of tangent lines. The details are explained in the CGPath API reference. Why two functions? Simple convenience? Is one ...

How to change Text Rotation Axis

I am using CGContextShowText to display text, but when rotation using CGAffineTransformation, the rotation axis is located at the left, not at the center of the drawn text, the code I am using is this: CGContextSaveGState(context); CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman); CGContextSetCharacterSpacing (context,...

What is the void* returned from CGBitmapContextGetData?

I'm trying to get the pixel information from an image and have got to the point where I have my void* data object which is a pointer to the image data. What exactly is this object? I've tried iterating over it hoping that it's an array of pixel info but it doesn't seem to work. I want to get the rgb values for each pixel. ...

How do I draw a point using Core Graphics?

I see APIs in Quartz for drawing lines and circles. But all I want to do is to specify the (x,y) cartesian coordinate to color a pixel a particular value. How do I do that? ...

Extracting 32-bit RGBA value from NSColor

I've got an NSColor, and I really want the 32-bit RGBA value that it represents. Is there any easy way to get this, besides extracting the float components, then multiplying and ORing and generally doing gross, endian-dependent things? Edit: Thanks for the help. Really, what I was hoping for was a Cocoa function that already did this,...

Affine Transformations vs Keyframing

This may be a silly question to a graphics guru (which I am not), but what's the difference between affine transformations and keyframing? I'm reading about the former in the iPhone cookbook, and she states that 'Affine transforms enable you to change an object's geometry by mapping that object from one view coordinate system into anothe...

How to render to offscreen bitmap then blit to screen using Core Graphics

I would like to render to an offscreen bitmap (or array of RGBA values) and then blit those to a UIView during in the view's drawRect function. I would prefer to do full 32-bit rendering (including alpha channel), but would also be content with 24-bit rendering. Would anyone mind pointing me in the right direction with some code snippet...

Core Animation with a Core Graphics drawing

I am inside a UIView subclass (CustomView in the code below). I am drawing a border around an image in a UIImageView subclass (containerView). The Core Graphics code for this is located inside drawInRect: in the subclass. The Core Animation transition is a flip, however when it is drawn, the Core Graphics code is not used, i.e. drawIn...

How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?

I have a UIImage (Cocoa Touch). From that, I'm happy to get a CGImage or anything else you'd like that's available. I'd like to write this function: - (int)getRGBAFromImage:(UIImage *)image atX:(int)xx andY:(int)yy { // [...] // What do I want to read about to help // me fill in this bit, here? // [...] int result = (red << 2...

Putting a CGImageRef on the clipboard

I'm trying to copy a CGImageRef to the clipboard pasteboard. I found a function that claims it should do this by creating a destination from (zero sized), adding the image to the destination, finalizing, then PasteboardPutItemFlavor the ref into the clipboard. However it doesn't work, so two questions: Is this the correct way to go ab...

How to create a font with CGFontCreateWithFontName?

I want to have a greater control on how and when fonts are loaded and released, therefore I'm interested in getting CGFontCreateWithFontName() to work. GContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSelectFont(ctx, "Georgia", 20.0, kCGEncodingMacRoman); // DRAWING WITH CGContextShowTextAtPoint() IS WORKING... GContextRef ...

How to reset to identity the "current transformation matrix" with some CGContext function?

I'm doing a series of translations and rotations on the CTM and at some point I need to reset it to identity before going further with transformations. I can't find any proper way to do it (obviously, there should have been a function named CGContextSetCTM or so) and since efficiency is the key, I don't want to use CGContextSaveGState/C...

Creating CGImageContext for resizing UIImage fails in simulator

I've got some code to resize a UIImage (in a category to UIImage), that first generates an Image Context: CGImageRef oldImage = [self CGImage]; CGSize oldSize = [self size]; CGContextRef context = CGBitmapContextCreate(NULL, //Data newSize.width, //Width newSize.height, //Height CGImageGetBitsPerComponent(oldImage), // Bits...

CGContextDrawImage draws image upside down when passed UIImage.CGImage

Does anyone know why CGContextDrawImage would be drawing my image upside down? I am loading an image in from my application: UIImage *image = [UIImage imageNamed:@"testImage.png"]; And then simply asking core graphics to draw it to my context: CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage); It renders in the ...

CGContext - is there a way to reset the current context

In my iPhone project, I've got a UIView where I implement the drawRect method: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); Inside the method I do a whole bunch of drawing of lines, images and texts using this context. The problem is that when I re-use this view, the context does not get re...

Font sizes in Core Graphics

Hello everyone, I'm trying to render a bit of text using Core Graphics APIs and I'm running into some conceptual difficulties. I'm trying to specify font size using CGContextSetFontSize. The size parameter is in something called "text space units". What is that? How does it map to "em" units? Thanks ...

Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

I'm writing an iPhone app, and I've got an image which I'ld like to have swirl outwards. Currently my code looks like this (wrapped in a beginAnimations/commitAnimations block): scale = CGAffineTransformScale(CGAffineTransformIdentity, 5.0f, 5.0f); swirl = CGAffineTransformRotate(scale, M_PI); [player setTransform:swirl]; [player s...

Event taps: Varying results with CGEventPost, kCGSessionEventTap, kCGAnnotatedSessionEventTap, CGEventTapPostEvent

I'm running into a thorny problem with posting an event from an event tap. I'm tapping for NSSystemDefined at kCGHIDEventTap, then replacing the event with a new one. The problem I'm running in to is that depending on how I post the event, it's being seen only by some applications. My test applications are Opera, Firefox, Quicksilver, an...

"kCGColorSpaceGenericRGB" is deprecated on iPhone?

I'm trying to get bitmap context with the following code: GContextRef MyCreateBitmapContext (int pixelsWide, int pixelsHigh) { CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitma...

UIImage imageNamed giving EXC_BAD_ACCESS the second time

Hi all, I'm working on a game with a bunch of mini games. Inside one gameview, I have the following code: UIImage* img = [UIImage imageNamed:@"foo.png"]; someImage = CGImageRetain(img.CGImage); [img release]; someImage is of type CGImageRef, and this has no issues the first time. After the user loses the mini game (or exits), the gam...