cgcontext

Painting on UIImageView with better performance

Hello :-) I have a view in which I paint a dotted line when the user moves their finger across the screen of the iPad/iPhone. I draw the line between a point stored as LastLocation, and the point that is the CurrentLocation. The drawings are to be persistant on the screen. This happens every time the touchMoved event is fired, and ends...

How can I draw a line through a point or to a point, where the line is always the same length (iPhone app dev)

I have a circular graph with a radial cursor on it, and the cursor moves to where you touch on the iPhone screen, but I need the cursor to remain the same length, even if the touch occurs close to the origin of the graph or outside the graph. I have no idea how to do this. Any help would be greatly appreciated ...

Core Text: counting pages in background thread

Let's say I'm writing text viewer for the iPhone using Core Text. Every time user changes base font size I need to count how many pages (fixed size CGRects) are needed to display the whole NSAttributedString with given font sizes. And I would like to do this in separate NSOperation, so that user does not experience unnecessary UI lags....

How do I use CGContext to draw on top of an existing UIView?

I have a subclass of UIView in which I've added some subviews to in my initWithFrame method. I've added a background, amongst other things. I want to draw some shapes on top of these views (which happen to cover the entire screen). But, when I implement drawRect: to draw these shapes, they didn't show up. Upon removing the other subvie...

How to save an image using UIImageWriteToSavedPhotosAlbum after it is transformed

Ok i have searched all over and I can't not seem to find the answer I need. :-( Here is what I am doing and what I need to happen. I have a UIImageView that I am able to transfrom using UIPanGestureRecognizer, UIRotationGestureRecognizer, and UIPinchGestureRecognizer all that works great. The problem comes when it is time to save those ...

Convert Image to B&W problem CGContext - iPhone Dev

Hello, I am using a method to convert images taken with the camera into black and white. The problem I'm running into is that if the picture is taken in Portrait mode, it rotates and stretches in the next view. But, if is taken in landscape it is just find. I can only duplicate this bug when I convert the image to Black And White. Here...

Saving CGContextRef

I have a drawing app in which I would like to create an undo method. The drawing takes place inside the TouchesMoved: method. I am trying to create a CGContextRef and push it to the stack OR save it in a context property that can be restored later but am not having any luck. Any advice would be great. Here is what I have ... UIIma...

Can I obtain a valid CGContext for drawing with just a @synthesize UIView dropped into a view controller view

Thank you in advance for any help, I am building a multipage iPad app,and each page has specialized calculations, they all work great, but i would like to make the user experience better with some simple line drawings that represent the calculations, I am comfortable with the drawing once i get a valid CGcontext working, and this is wher...

iOS4: how do you set a CGContext's transormation matrix to an absolute number?

I'm currently making a graphical application, and it will make my life a lot easier if I simply flip the context's transform matrix upside down whenever I want to draw something upside down, which is quite frequently. However, the only command I can find that supports this is CGContextScaleCTM. This is fine I guess, but it's an additive ...

How do i print a image in images tiles in Cocoa printing

I had Carbon code which prints image as tiles in . But now for 64 bit i want to change that into carbon. I have a CGContext which i need to print and which holds the new tile every time. I cant find a suitable workflow. Any help would appreciated ...

How to convert NSData to CGDataProviderRef on iphone sdk?

I am getting EXEC_BAD_ACCESS errors in a CGContextDrawImage call and trying to trace it back. I have a PNG image and running a UIImagePNGRepresentation o it gives me NSData instance. I need to convert this to CGImageRef instance, so I can run the CGImageCreateWithPNGDataProvider method with this CGImageRef. I tried two ways: 1) To cast...

Draw a line in iPhone , Exception

Im trying to draw a line . I wrote a code like below. UIColor *currentColor = [UIColor blackColor]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, currentColor.CGColor); CGContextMoveToPoint(context, startingPoint.x, startingPoint.y); CGContextAdd...

CGContext & CGBitmapContextCreateImage errors, how to fix?

I've been at this for hours now, and don't even know how to debug this error. Maybe there's an SO expert who knows what's going on. - (void) prepareSubset { CGSize size = [image size]; float scale = fminf(1.0f, fmaxf(SUBSET_SIZE / cropRect.size.width, SUBSET_SIZE / cropRect.size.height)); CGPoint offset = CGPointMake(-cropRect.origin....

Efficient, best way to copy a bitmap context?

I have a bitmap context (iPhone/iOS) I am using for offscreen drawing prior to formal rending to a UIView. I'd like to make a copy of the bitmap context prior to performing drawing operations (and ultimately render) in the event I need to do a revert. I haven't found a Quartz API that allows me to easily copy a bitmap context, but mayb...

iPhone MapKit: Custom MKPolygonView with image draws upside down

Hi, does anybody know what to do with this problem: my image in a custom MKPolygonView is flipped upside down? The idea (this is working OK already) is having an class "SnowmapsOverlayView" that extends "MKPolygonView", that displays a image. This image has a default location & size on the map (acts as a GroundOverlay in the Google Map...

Draw Line in View : Not Drawing

I am trying to draw a line my Code is this -(void) drawRect:(CGRect) rect { NSLog(@"Reached Draw ARect Function"); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(ctx, 2.0); CGContextSetRGBStrokeColor(ctx, 1.0, 2.0, 0, 1); CGContextMoveToPoint(ctx, 0, 0); CGContextAddLineToPoint( ctx, ...

transparency/alpha in CoreGraphics context (iphone, objc)

Hello, I am currently making a basic image editor for iphone. I take the CGImageRef from a UIImage and create a context for it using the following code origImage = result.CGImage; Iheight = CGImageGetHeight(origImage); Iwidth = CGImageGetWidth(origImage); IcolorSpace = CGColorSpaceCreateDeviceRGB(); IrawData = malloc(Iheight * Iwidth...

iPad Obj-C Sketch Application Slow Performance

Hey everyone, I'm trying to whip up a sketch application for the iPad so that I can draw with my finger. I've got a problem that the performance is atrocious. I've pasted a snippet of the core of my code below. In reality it's a bit more complicated. Does anyone know off the top of their heads why this CGContext stuff is slow? I'd appr...

error when trying to undo Context

i try to undo myContext from save state then after i draw the line i call undo method to restore my context to previous but it report error <Error>: CGContextRestoreGState: invalid context code - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = ...

Multiplying RGBA with two CGImageRefs

I'd like to multiply r, g, b and a values of two CGImages, to use a single image as both a mask (in its alpha channel) and tint (in the rgb channels). I first tried simply: CGContextDrawImage(context, CGRectMake(0, 0, _w, _h), handle()); CGContextSetBlendMode(context, kCGBlendModeMultiply); CGContextDrawImage(context, CGRectMake(0, 0, o...