core-graphics

iPhone - Jagged Edges when applying perspective to CALayer

I have a CALayer that I apply a perspective to using a CGTransform3D and specifying the m14 property. When the perspective is applied, the layer has jagged edges. I've heard people mention that adding a 1px transparent border around the layer will help with this. I don't know how to do that. I have tried using the border and borderWi...

Creating a mask from a graphics context

I want to be able to create a greyscale image with no alpha from a png in the app bundle. This works, and I get an image created: // Create graphics context the size of the overlapping rectangle UIGraphicsBeginImageContext(rectangleOfOverlap.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); // More stuff CGContextDrawImage(ctx...

How to- NSAttributedString to CGImageRef

Hello! I'm writing a QuickLook plugin. Well, everything works. Just want to try it make better ;). Thus the question. Here is a function that returns thumbnail image and that I'm using now. QLThumbnailRequestSetImageWithData( QLThumbnailRequestRef thumbnail, CFDataRef data, CFDictionaryRef properties); ); http://developer.apple.com/m...

On OSX, how do I gradient fill a path stroke?

Using the plethora of drawing functions in Cocoa or Quartz it's rather easy to draw paths, and fill them using a gradient. I can't seem to find an acceptable way however, to 'stroke'-draw a path with a line width of a few pixels and fill this stroke using a gradient. How is this done? Edit: Apparently the question wasn't clear enough. T...

Mirroring a portion of the screen to an external display (in OSX)

I would like to write a program that can mirror a portion of the main display into a new window. Ideally this new window could then be displayed on an external monitor. I have seen this uiltity for a flightsim that does this on a pc (a multifunction display extractor). CLick here for a screenshot of the program (MFD Extractor) This w...

How do I get a CGAffineTransformMakeScale to shrink a view around its center?

This should be an easy one -- when I use a CGAffineTransformMakeScale on a UIView with width and height = 0.5, it shrinks to the upper left. I need it to shrink around its center. What do I need to do? Thanks! ...

Drawing gradients on a UIView doesn't work on subsequent calls to drawRect:

I'm trying to debug an issue that is really stumping me. Basically, I have a UIView subclass that draws a gradient to itself in drawRect: based on colors that i provide in the init method. The problem occurs when the view draws itself again. If i call setNeedsDisplay on the view, or if say the view is removed due to an out of memory w...

Draw rectangle using Core Graphics with live preview

I'm creating a simple drawing application and would like some help with drawing rectangles based on the user's touch events. I'm able to draw a rectangle using Core Graphics from the point in touchesBegan to the point in touchesEnded. This rectangle is then displayed once the touchesEnded event is fired. However, I would like to be abl...

masking a UIImage

I'm working on an app that can change the borders or a rectangular UIImage. The borders will vary, but will look like the UIImage was cut out with scissors, or something to that affect. What is the best way to do this? My first thought is to prep a bunch of transparent PNGs with the correct border effect I'm looking for, and then someh...

renderInContext creating memory that is not promptly released

While debugging in instruments using 'ObjectAlloc' I'm noticing 7megs of memory being allocated for the renderInContext call, but it never is released. When I comment out the renderInContext call this doesn't happen, and future renderInContext calls does not continue to increase the memory allotment. UIGraphicsBeginImageContext(contentH...

How can I make image brighter (more light as flash effect) using Core Graphics

How can I get flash effect for images got from Camera? After I got image from camera (it shows in UIImageView) and before saving it as a file I'd like to lighten (in some cases) image by pressing Flash button. Is it possible by using Core Graphics ?? ...

CGContextRef getting corrupted in plugins

Here's a picture of one of the stranger problems I've had. I'm using a plugin architecture to draw things in Core Graphics. The host app creates a context that is passed to the plugin, which draws into the context and sends it back. Here this was done multiple times to draw multiple objects (though just for demonstration, it happens even...

How can I tell when a UIWebView has finished drawing to a context?

In my code I'm trying to show a UIWebView as a page is loading, and then, when it's done, capture an image from the web view to cache and display later (so I don't have to reload and render the web page). I have something along the lines of: CGContextRef context = CGBitmapContextCreate(…); [[webView layer] renderInContext:context]; CG...

How to smooth the edge of a zig-zag line?

Currently I draw a zig-zap line by CGContextMoveToPoint, CGContextAddLineToPoint, and CGContextStrokePath, following touchesMoved events. How can I smooth the edges of the line? Such that when the user draw a circle-like shape, the circle can be more round'ed. The GLPaint example use OpenGL, is that the only way to do it? ...

Implementation custom view and CoreGraphics

I'm implementing custom view which will provide image editing functionality (like filling with color, hand drawing etc). View initialized with image (pgn, jpg whatever), and user can modify it. I'm not sure how it will be good to implement. At the moment every drawRect I draw UIImage *mainImage. During events like touchesEnded:withEve...

CATiledLayer: Determining levelsOfDetail when in drawLayer

I have a CATiledLayer inside a UIScrollView and all is working fine. Now I want to add support for showing different tiles for three levels of zooming. I have set levelsOfDetail to 3 and my tile size is 300 x 300. This means I need to provide three sets of tiles (I'm supplying PNGs) to cover: 300 x 300, 600 x 600 and 1200 x 1200. My pr...

Reinterpret a CGImageRef using PyObjC in Python

Hi, I'm doing something that's a little complicated to sum up in the title, so please bear with me. I'm writing a Python module that provides an interface to my C++ library, which provides some specialized image manipulation functionality. It would be most convenient to be able to access image buffers as CGImageRefs from Python, so they...

Not drawing outside bounds when clipToBounds=NO

I am drawing lines on a map, and I notice that my annotation view isn't covering the entire area of the lines (which is fine, as long as I can draw outside the bounds of the view). Here is a picture of what I'm experiencing. The clipToBounds property is set to NO for the annotation view, and I've added a semi-transparent color to the b...

iPhone: no way to draw on screen outside drawRect?

Is there a way to draw on the iPhone screen (on a UIView in a UIWindow) outside of that view's drawRect() method? If so, how do I obtain the graphics context? The graphics guide mentions class NSGraphicsContext, but the relevant chapter seems like a blind copy/paste from Mac OS X docs, and there's no such class in iPhone SDK. EDIT: I'm...

Fluid iPhone Animation ala Plants vs Zombies

If you've played Plants vs Zombies, you've seen how fluid and remarkable the character animation is. Can anyone assume how they are doing this? They don't seem to simply be animating bitmaps; the animation is too crisp, even as characters rotate and scale. The artwork looks vector, but I can't imagine that everything is drawn out using C...