core-graphics

Can't add a corner radius and a shadow

Hiya, I'm trying to draw a shadow and a corner radius on an image. I can add them separately, but I've got no way to add both effects at the same time. I'm adding a shadow with: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; Here, layer is a CALaye...

What could be wrong with my CGBitmapContextCreateImage() or UIGraphicsGetImageFromCurrentContext() call?

Same problem as this guy I'm trying to use CGBitmapContextCreateImage() or UIGraphicsGetImageFromCurrentContext(), but they leak badly, even if I don't do anything in the context. When I run this in a UIView subclass, before setNeedsDisplay: UIGraphicsBeginImageContext(CGSizeMake(320, 264)); // Optional drawing code here, but still lea...

Annotation in UIWebview in iphone sdk

Hello all, I need help for, scribbling on the webpage i.e where ever the user moves on the uiwebview there it should draw a line according to the touch moves. Is this possible. Can any one please help me in this. Thanks, Mrudula. ...

CTFramesetterSuggestFrameSizeWithConstraints sometimes returns incorrect size?

In the code below, CTFramesetterSuggestFrameSizeWithConstraints sometimes returns a CGSize with a height that is not big enough to contain all the text that is being passed into it. I did look at this answer. But in my case the width of the text box needs to be constant. Is there any other/better way to figure out the correct height for ...

Using image created with CGBitmapContextCreate as an opengl texture

Hi! I'm generating an image using quartz 2d and I want to use it as an opengl texture. The tricky part is that I want to use as few bits per pixel as possible, so I'm creating cgContext as following: int bitsPerComponent = 5; int bytesPerPixel = 2; int width = 1024; int height = 1024; void* imageData = malloc(width * height * bytesPerP...

how do I get a PDF object (string,image,etc) that was touched by user?

I am using CGPDF* set of classes to read a pdf document, is there a way to extract the object that was touched ('clicked') by user? In other way is there a way to get a PDF / (Quartz?) object at certain coordinates? ...

CGImageGetWidth returns different size then actual image

Hi i have a lot of image reading in my app and when I load the files i use CGImageGetWidth and CGImageGetHeight to get the sizes of the images. However this does not seem to return the right values all the time. For example if I have an image whose size is 114x14, these functions will return 126x22 or something random like that. The r...

Help drawing circle in iPhone

The following is a snippet of code where I am trying to draw a circle but my x value prints as a constant value. It's most likely something very very simple. Thanks in advance for any help. int sides = 100; int radius = 200; int centerX = 100; int centerY = 100; CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f}; CGContextSetStrokeColor(context,...

Porting Quartz 2d python demo to pure Core Graphics C

Hi folks, let me first off noting that I have absolutely no idea what I'm doing with objective-c and mac development (though I'm fine with c). I made a wonderfully simple graphics utility on leopard with the Quartz-2d binding for python: http://developer.apple.com/graphicsimaging/pythonandquartz.html that basically inputs a text file ...

Best way to make a UIVIew look like a UIView in IB?

Hi, I'm trying to make resizable UIViews of which users can resize (code is done for that) and drag it around. Now I need to make it look like what it looks like in IB, with circles at its corners to drag, and dotted lines as borders of the UIView. How do you think I should go about doing this? Many thanks. ...

Alternative to CGPathGetPathBoundingBox() for iPad (iOS 3.2)

I'm trying to get my head around using QuartzCore to render semi-complex text/gradient/image UITableViewCell composites. Thankfully, Opacity will let me visually build the view and then spit out source code to drop in to cocoa touch. Trouble is, Opacity assumes the code is running on iOS 4, which is a problem if you want to draw Quartz...

Does CGContextSetTextMatrix work for offscreen bitmaps?

I'm creating an image offscreen using a context from CGBitmapContextCreate(). While drawing text, I tried to use the: CGContextSetTextMatrix(contextRef, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); but my text was still upside down. If I used the standard transforms it was correct: CGContextTranslateCTM(contextRef, 0.0, co...

kCGErrorFailure: unknown error code: invalid memory allocation

I'm getting a strange CoreGraphics error from the following code: NSView *docView = [[[webView mainFrame] frameView] documentView]; NSSize s = [docView bounds].size; [[docView window] display]; [[docView window] setContentSize:s]; // Commenting this line removes the errors. Here are the errors: a.out[20033] : unknown error code: inva...

Drawing a 'turning wheel' using Core Graphics?

Can someone provide an example of drawing an iPhone-like turning wheel using Core Graphics. I know it can be done by drawing a sequence of lines but that requires a math formula to work out line points. Can someone help me with that? Here is how it should look like: It looks like it is made up of several lines with rounded edges and ...

What are some great Quartz 2D drawing tutorials?

I'm searching for some great Quartz 2D drawing tutorials aimed at the iPhone. I'm new to Quartz and want to start off with something easy and then progress to more difficult stuff. Does anyone know of any Quartz 2D drawing tutorials that they would recommend? ...

Force clockwise/anticlockwise rotation for a CABasicAnimation of a UIImageView

I'm animating a pendulum which swings from 0 degrees to max 200 degrees and then back again. The problem is that if the pendulum goes over 180 degrees, it returns to 0 by the shortest route which is to continue clockwise. And I'd like it to go anticlockwise. Here's my code: ('right' is a boolean which is TRUE when the pendulum is swingin...

Dissasembling simple ARM instructions?

I've been messing around with IDA Pro and trying to disassemble my own products just for the sake of it. I've noticed a couple of things I don't understand because my assembly language knowledge is terrible. Here is a little chunk of code which invokes CGContextSetRGBStrokeColor. CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1); In IDA i...

How can I save a Bitmap Image, represented by a CGContextRef, to the iPhone's hard drive?

I have a little sketch program that I've managed to throw together using Quartz2D, but I'm very new to the iOS platform and I'm having trouble figuring out how to allow the user to save their sketch. I have a CGContextRef that contains the sketch, how can I save it so that it can later be retrieved? Once it's saved, how can I retrieve ...

Drawing a line in a UIView subview

I have a UIView subclass. This subclass has multiple subviews. Is it possible to draw a line using core graphics inside a subview that is part of the uiview subclass? For example, I have a SampleView class, which is a subclass of UIView. Inside this class's header file is the property for UIView *sampleSubView, which is a subview of Sam...

How to rotate the imageView in a UIButton, and NOT scale it.

I am endeavouring to rotate the imageView property of a UIBUtton without scaling it. The image in question is 24x18 - wider than it is tall - but once rotated into place the image is being scaled to keep those dimension - leaving me with a very squished image. How can I prevent this? Below is my code .. -(IBAction)rotateButton { NSLog...