cgcontext

When is a CGBitmapContext not a BitmapContext?

I have a CGContext that I create with CreateARGBBitmapContext from here. When I do CGBitmapContextGetBitsPerComponent it tells me 8 bits per component (Which is correct) However, when I do CGBitmapContextGetBitmapInfo or CGBitmapContextGetData, I get NULL. Those are only supposed to give NULL when the context isn't a bitmap context. How...

iphone: masking an image using paths

How do you mask an image using paths? What Im trying to do is draw a line using CGContextStrokePath and show only those parts of a CGLayerRef which are under it. Also, how do you erase only those parts of the CGLayerRef which are under it? Thanks. ...

iPhone: Transforming an image using Quartz 2D

I am trying to apply some transformations on images using a CGContextRef. I am using CGContextTranslateCTM, CGContextScaleCTM and CGContextRotateCTM functions, but to keep things simple lets focus on just the first. I was wondering why the following code produces exactly the original image?! Am I missing something? CGColorSpaceRef color...

Filling a shape with a gradient in CGContext

I want to fill a polygon shape that I have drawn via Core Graphics with a linear CGGradient. The CGContextDrawLinearGradient function draws a gradient from one point to another but it fills the entire view. How can I display the gradient only inside the polygon shape I have drawn? ...

CALayer drawInContext vs addSublayer

How can I use both of these in the same UIView correctly? I have one custom subclassed CALayer in which I draw a pattern within drawInContext I have a another in which I set an overlay PNG image as the contents. I have a third which is just a background. How do I overlay all 3 of these items? [self.layer addSublayer:bottomLayer]; ...

Iphone CGContextShowTextAtPoint for Japanese characters

Hi, I am working on an app where I am using CGContextShowTextAtPoint to display text to the screen. I want to also display Japanese characters, but CGContextShowTextAtPoint takes as its input a C string. So either A) How do I change Japanese characters into a C string? If this is not possible, B) How can I manually print Japanese charac...

Simple iPhone drawing app with Quartz 2D

I am making a simple iPhone drawing program as a personal side-project. I capture touches event in a subclassed UIView and render the actual stuff to a seperate CGLayer. After each render, I call [self setNeedsLayout] and in the drawRect: method I draw the CGLayer to the screen context. This all works great and performs decently for d...

How do I draw multiple CGContextRefs to -drawRect?

I have saved a bunch of CGContextRefs and I want to draw all of these out in the drawRect portion of my UIView. How can I do this? ...

Flatten UIViews Subviews to UIImage iPhone 3.0

I have a UIView that has several UIImageViews as subviews. Each of these subviews has had different affine transform applied. I would like to take what amounts to a screen capture of my UIView, capturing it as a UIImage, or some other image representation. The method I have tried already, rendering the layers to a CGContext with: [v...

Saving and restoring CGContext

I'm trying to save and restore cgcontext to avoid doing heavy drawing computations for a second time and I'm getting the error : CGGStackRestore: gstack underflow. What am I doing wrong? What is the correct way to do this? - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); if (initialized) { ...

iphone sdk- UIGraphics - how to select a superview as current drawing context

hello, i'm trying to draw a line from the originate point of an image view to its destination point. my problem is (i guess) how to set the superview as current drawing context (from the image view). can someone help please. this is the code i'm using in image view.. //UIGraphicsPopContext(); CGContextRef context = UIGraphicsGetCur...

How can I draw tinted translucent images in iPhone SDK?

For the visuals in my iPhone application I'm compositing UIImages in a transparent UIView. I'd like the images to appear in their normal colors sometimes, but under other conditions I want them to be drawn tinted red. This is easy to do with opaque square images, but parts of my images are translucent, and I only want to tint the solid p...

Writing YUV data into a CGContext

How can I write a YUV frame data into a CGContext? ...

To select a context

How can I select the context of a specific UIView among the several ones I have on my screen and quartz draw on it? ...

Preserve line width while scaling all points in the context with CGAffineTransform

Hi there, I have a CGPath in some coordinate system that I'd like to draw. Doing so involves scaling the old coordinate system onto the Context's one. For that purpose, I use CGContextConcatCTM() which does transform all the points as it should. But, as it is a scaling operation, the horizontal/vertical line widths get changed to. E.g. ...

Search a photo for drawing

I want to be able to do something like take a picture of a chalkboard and search for what the teacher wrote and then delete the chalkboard and make like a CGContext Path of what the teacher wrote, or just have what the teacher wrote ...

How to use NSUndoManager with a UIImageView or CGContext

I have an app that uses cgcontext to draw things onto a UIImageView that the user draws using touch events, and I want to be able to undo the drawings made by the user. Edit: I am trying to use my touchesBegan to save theUIImage at the begining of a touch to the NSUndoManager And then how do I use it to undo using a UIAlertView. Mea...

Is it possible to make a pattern for a CGContext Path using a png

I want to make a path that has a png as it's pattern, or if you could or think it would be easier to make my own pattern, then tell me that also. I will be greatful to anyone who can put up some code. Thanks in advance ...

How would I save a CGContext into an NSUndoManager

I want to be able to save a CGContext into my NSUndoManager using these methods - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; currentPoint.x = currentPoint.x; currentPoint.y = currentPoint.y; ...

How do I stroke a CGContext path with multiple random images

I want to stroke a CGContext path using three or four images, but randomly cycle through the images as I'm drawing the path. I want to draw the images INSTEAD!! of drawing the CGContext I am now. I have this code so far - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPo...