core-graphics

How i access the array of CGPoints to draw the graph?

Hi, I have the code in which i want to develop the graph.The code is, NSArray *coordinate = [[NSArray alloc] initWithObjects: @"42,213", @"75,173", @"108,153", @"141,133", @"174,113", @"207,73", @"240,33", nil]; CGContextSetRGBFillColor(ctx, 255, 0, 0, 1.0); CGContextSetLineWidth(ctx, 8.0); for(int intIndex = 0; intIndex < [coordinate c...

GLPaint Problem with OPENGL and Core Graphics Frameworks

I am a newbie trying to use OpenGl. I began by trying to write something similar to GLPaint. However, the moment I import the OpenGL framework, I get errors referring to missing information from Core Graphics but I cannot import Core Graphics since it is not in the list of existing frameworks. I understand it is in ApplicationService...

setNeedsDisplayInRect: paints a white rectangle only

Hi, I'm still a little fresh to CoreGraphics programming, so please bear with me. I'm trying to write an application, which allows the user to rub stuff off an image with the finger. I have the basic functionality nailed down, but the result is sluggish since the screen is redrawn completely every time a touch is rendered. I did some re...

Core Graphics Rotating a Path

This should be a simple one, basically I have a few paths drawn with core graphics, and I want to be able to rotate them (for convenience). I've tried using CGContextRotateCTM(context); but it's not rotating anything. Am I missing something? Here's the source for drawRect - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphic...

iPhone app crashes on start-up, in stack-trace only messages from built-in frameworks

My app some times crashes at start-up. In stack-trace only messages from built-in frameworks. An excerpt from a crash log: OS Version: iPhone OS 3.1.3 (7E18) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x000e6000 Crashed Thread: 0 Thread 0 Crashed: 0 CoreGraphics ...

iPhone: CoreGraphics and memory management

Can someone tell me what I am doing wrong here? I use this method to flip through pages in a PDF. But something in the code seems to not be released properly because every-time I pull a PDF page that contains an image my memory footprint increases. I am fairly new to CoreGraphics, and can't for the life of me figure out where this method...

Equivalent of CGPoint with integers?

Cheers, I like strict typing in C. Therefore, I don't want to store a 2D vector of floats if I specifically need integers. Is there an Apple-provided equivalent of CGPoint which stores data as integers? I've implemented my type Vector2i and its companion function Vector2iMake() à la CGPoint, but something deep in me screams that Apple ...

trying to draw scaled UIImage in custom view, but nothing's rendering

I've created a custom view class and right now just want to draw an image scaled to fit the view, given a UIImage. I tried just drawing the UIImage.CGImage, but as others have attested to on this site (and in the docs), that renders the image upside down. So, at the suggestion of an answer I found to another question, I'm trying to dra...

Drawing performance with CGImageCreateWithJPEGDataProvider?

I've actually curious about this for the iPhone. I am getting an MJPEG stream from a server and trying to render it natively on the iphone (without the use of safari class). Reasons for this is because the safari class while CAN render MJPEG natively, does not do so at the framerate I would like. So I tried drawing it natively, but I've...

question about CGAffineTransformTranslate

CGRect rect1 = backgroundImageView.frame; NSLog(@"%f,%f,%f,%f",rect1.origin.x,rect1.origin.y, rect1.size.width,rect1.size.height); angle = -90.0; moveX = 0; moveY = 0.0; CGFloat degreesToRadians = M_PI * angle / 180.0; CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadians); lan...

Strange crashes on the iPad device with core graphics functions

I am getting a lot of strange EXC_BAD_ACCESS crashes on the iPad that only happen on the device and not in the simulator. I am assuming that they are somehow memory related, but I am not sure. They all happen with image context related functions. One strange example is using CGImageCreateWithImageInRect. For example, if i run through a ...

Render layer offscreen

How can I create/prepare a CALayer offscreen, so that when the page is displayed, then all it has to do is to display the prepared layer? ...

UIImage change raw pixels from white to clear?

I've tried some code from each of these questions: How to make one color transparent on a UIImage? How to mask a UIImage so that white becomes transparent on iphone? but have come up unsuccessful, unfortunately working with Core Graphics and images is not my strong suit. How would I go about accessing a UIImage's raw data and changin...

Draw underlined / strikethrough text ( MULTILINE STRING ) ?

Hi, I have to draw underlined-multiline text with all types of text alignment. I have searched on forums and got some results like: http://davidjhinson.wordpress.com/2009/11/26/underline-text-on-the-iphone/ http://forums.macrumors.com/showthread.php?t=561572 But all draw text for single line only. while i have multi-line text. The si...

Why are all my masked views unmasked in my view snapshot?

I'm taking a snapshot of an view. This view has got some subviews which have layer masks applied to them. For some reason, those masks take no effect in the snapshot and the masked parts are completely visible. UIGraphicsBeginImageContext(theView.frame.size); [theView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *newIma...

Why are my lines getting thicker and thicker?

I try to draw some lines with different colors. This code tries to draw two rectangles with 1px thin lines. However, the second rectangle is drawn with 2px width lines, while the first one is drawn with 1px width. - (void)addLineFrom:(CGPoint)p1 to:(CGPoint)p2 context:(CGContextRef)context { // set the current point CGContex...

How to judge the color of UILabel?

UILabel *templabel = [self.wallBoxArray objectAtIndex:i]; for( int i = 0 ; i < [self.wallBoxArray count]; i++) { if(templabel.backgroundColor == [UIColor greenColor]) { NSLog(@"the color isn green"); } } There are many label's in my array. They all initialized with green color. But i judged that way ,why cant print " th...

How to compensate the flipped coordinate system of core graphics for easy drawing?

It's really a pain, but always when I draw an UIImage in -drawRect:, it's upside-down. When I flip the coordinates, the image draws correctly, but at the cost of all other CG functions drawing "wrong" (flipped). What's your strategy when you have to draw images and other things? Is there any rule of thumb how to not get stuck in this p...

Overlays with MkMapView do not scroll smoothly

By overriding the drawrect of my MkAnnotationViews, I am displaying paths using CoreGraphics. The problem I have is when I zoom in pretty close and scroll the map view, the paths drawn by CoreGraphics seem to be really jumpy, as if they are updated only after a shift of three or more pixels. When zoomed out, the scrolling is perfectly sm...

How do I pick the control point when using CGContextAddCurveToPoint to make a line graph with curves

I'm making a line graph on the iphone using core graphics and instead of having a jagged chart, I want to smooth it out like in good old math class. What's the formula to pick where to put the control points for CGContextAddCurveToPoint? CGFloat cp2x = (x + x + prevX); CGFloat cp1y = (prevY + prevY + y); CGF...