Search Results

Search found 64 results on 3 pages for 'cgcontext'.

Page 1/3 | 1 2 3  | Next Page >

  • Quartz 2D: draw from a CGContext to another CGContext

    - by alexey
    I have a CGBitmapContext (bitmapContext) and I would like to draw some rectangle part (rect) of it to the current CGContext (context). Right now I do that way: CGContextRef context = UIGraphicsGetCurrentContext(); CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext); CGContextClipToRect(context, rect); CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage); CGImageRelease(cgImage); Is it optimal? What is the best way to do it?

    Read the article

  • Using CGContext to display a sprite sheet iPhone

    - by Mike
    Hello, So I have a spritesheet in png format, and have already worked out the coordinates for what I want to display. I'm trying to create a method that will return a UIImage when passed the location information on the spritesheet. I'm just not sure how to use the CGContext stuff along with the the coordinates to return an UIImage. I was looking to CGContextClipToRect because I think that is the way to do it, but I just can't seem to get it to work. Something like this CGSize size = CGSizeMake(xSize, ySize); UIGraphicsBeginImageContext(size); //CGContextClipToRect(spriteSheet.size, imageRect); [spriteSheet drawAtPoint:CGPointMake(xPos, yPos)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; returns only what is in the size Context. I need to be able to "move" this size window around the spritesheet if that makes sense. Any help would be appreciated. Thanks, Mike

    Read the article

  • iPhone CGContext: drawing two lines with two different colors

    - by phonecoddy
    I am having some troubles using the CGContext with an iPhone app. I am trying to draw several lines with different colors, but all the lines always end up having to color, which was used last. I tried several approaches I could think of, but haven't been lucky. I set up a small sample project to deal with that issue. This is my code, I use in the drawRect method. I am trying to draw a red and a blue line: - (void)drawRect:(CGRect)rect{ NSLog(@"drawrect!"); CGContextRef bluecontext = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(bluecontext, 2.0); CGContextSetStrokeColorWithColor(bluecontext, [UIColor blueColor].CGColor); CGContextMoveToPoint(bluecontext, 1, 1); CGContextAddLineToPoint(bluecontext, 100, 100); CGContextSetStrokeColorWithColor(bluecontext, [UIColor redColor].CGColor); CGContextAddLineToPoint(bluecontext, 200, 100); CGContextStrokePath(bluecontext); } thanks for your help

    Read the article

  • CGContext problems

    - by Peyman
    Hi I have a CALayer tree hierarchy A B C D where A is the view's root layer (and I create and add B,C and D layers. I am using the same delegate method `- (void) drawLayer:(CALayer *) theLayer inContext:(CGContextRef)context to provide content to each of these layers (implemented through a switch statement in the above method). At initiation A's content is drawn (A.contents) sequentially through these methods `- (void) drawLayer:(CALayer *) theLayer inContext:(CGContextRef)context -(void) drawCircle:(CALayer *) theLayer inContext:(CGContextRef)context where drawCircle does CGContextSaveGState(context); / draws circle and other paths here / CGContextRestoreGState(context); CGImageRef contentImage = CGBitmapContextCreateImage(context); theLayer.contents = (id) contentImage; CGImageRelease(contentImage); (i.e I save the Context, do the drawing, restore the context, make a bitmap of the context, update the layer's contents, in this case A's, then release the contentimage). When the user then clicks somewhere in the circle at touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event delegate method I then try to paint the content of B by (still in touchesEnded:) CGContextRef context = UIGraphicsGetCurrentContext(); [self drawLayer:self.B inContext:context]; [self.B setNeedsDisplay]; the setNeedsDisplay call the delegate - drawLayer:(CALayer *) theLayer inContext:(CGContextRef)context again but this time the switch statement (using a layer flag) calls [self drawCircle:theLayer inContext:context]; with color red. The problem I am facing is that when -drawCircle: inContext: is called I get a long list of CGContext errors, starting with <Error>: CGContextSaveGState: invalid context and ending with CGBitmapContextCreateImage: invalid context I played around with making context the view's ivar and it worked so i am sure the context is the problem but I don't know what. I've tried CGContextFlush but it didn't help. Any help would be appreciated thank you

    Read the article

  • Drawing triangle/arrow on a line with CGContext

    - by Pete
    Hi, I am using the framework of route-me for working with locations. In this code the path between two markers(points) will be drawn as a line. My Question: "What code should I add if I want to add an arrow in the middle(or top) of the line, so that it points the direction" Thanks - (void)drawInContext:(CGContextRef)theContext { renderedScale = [contents metersPerPixel]; float scale = 1.0f / [contents metersPerPixel]; float scaledLineWidth = lineWidth; if(!scaleLineWidth) { scaledLineWidth *= renderedScale; } //NSLog(@"line width = %f, content scale = %f", scaledLineWidth, renderedScale); CGContextScaleCTM(theContext, scale, scale); CGContextBeginPath(theContext); CGContextAddPath(theContext, path); CGContextSetLineWidth(theContext, scaledLineWidth); CGContextSetStrokeColorWithColor(theContext, [lineColor CGColor]); CGContextSetFillColorWithColor(theContext, [fillColor CGColor]); // according to Apple's documentation, DrawPath closes the path if it's a filled style, so a call to ClosePath isn't necessary CGContextDrawPath(theContext, drawingMode); }

    Read the article

  • What way to use the CGContext to draw is suitable?

    - by Tattat
    I know that the CGContext cannot call it to draw directly, and it needs to fill the drawing logic in the drawInContext, and call the CGContext to draw using "setNeedsDisplay", so, I designed a cmd to execute, but it cause some problems... like this : http://stackoverflow.com/questions/2617827/why-i-cant-draw-in-a-loop-using-uiview-in-iphone I think the CGContext is very different from my previous programming experience....(I used HTML5 canvas, that allow me add more details, after I draw, so do the Java Swing) Actually, I want to know what is the suitable to implement these kind of thing in Apples' programmer mind. Thz.

    Read the article

  • CenterPoint in CGContextAddArc ?

    - by Mikhail Naimy
    Hi , i am drawing Arc through CGCOntext.I want to draw a string in the center Point of Arc.how can i fond the center point in the Arc which has been drawn through CGContext. CGContextSetAlpha(ctx, 0.5); CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha ); CGContextMoveToPoint(ctx, cX, cY); CGContextAddArc(ctx, cX, cY, radious+10, (startDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); CGContextClosePath(ctx); CGContextFillPath(ctx);

    Read the article

  • CGContext - PDF margin

    - by Manoj Khaylia
    Hi All I am showing PDF content on a view using this code using Quartz Sample // PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system // before we start drawing. CGContextTranslateCTM(context, 0.0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); // Grab the first PDF page CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNo); // We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing CGContextSaveGState(context); // CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any // base rotations necessary to display the PDF page correctly. CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true); // And apply the transform. CGContextConcatCTM(context, pdfTransform); // Finally, we draw the page and restore the graphics state for further manipulations! CGContextDrawPDFPage(context, page); CGContextRestoreGState(context); Using this all works fine I want to set the margin for the PDF context, bydefault it showing 50 px margin in every side.. I have tried CGContext methods but not got the appropriate one. Can any body help me regarding this Thanks Monaj

    Read the article

  • Problem in cropping the UIImage using CGContext?

    - by Rajendra Bhole
    Hi, I developing the simple UIApplication in which i want to crop the UIImage (in .jpg format) with help of CGContext. The developed code till now as follows, CGImageRef graphicOriginalImage = [originalImage.image CGImage]; UIGraphicsBeginImageContext(originalImage.image.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGBitmapContextCreateImage(graphicOriginalImage); CGFloat fltW = originalImage.image.size.width; CGFloat fltH = originalImage.image.size.height; CGFloat X = round(fltW/4); CGFloat Y =round(fltH/4); CGFloat width = round(X + (fltW/2)); CGFloat height = round(Y + (fltH/2)); CGContextTranslateCTM(ctx, 0, image.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); CGRect rect = CGRectMake(X,Y ,width ,height); CGContextDrawImage(ctx, rect, graphicOriginalImage); croppedImage = UIGraphicsGetImageFromCurrentImageContext(); return croppedImage; } The above code is worked fine but it can't crop image. The original image memory and cropped image memory i will got same(equal to original image memory). The above code is right for cropping the image?????????????????? How i cropping the image (in behind pixels should also be crop) from the center of the image???????????? I already wasting a lot of time for developing the above code , but i didn't get answer or way to find out how to crop the image.Thanks for sending me answer in advanced.

    Read the article

  • CGContextDrawPDFPage doesn't seem to persist in CGContext

    - by erichf
    I am trying to access the pixels of a CGContext written to with a PDF, but the bitmap buffer doesn't seem to update. Any help would be appreciated: //Get the reference to our current page pageRef = CGPDFDocumentGetPage(docRef, iCurrentPage); //Start with a media crop, but see if we can shrink to smaller crop CGRect pdfRect1 = CGRectIntegral(CGPDFPageGetBoxRect(pageRef, kCGPDFMediaBox)); CGRect r1 = CGRectIntegral(CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox)); if (!CGRectIsEmpty(r1)) pdfRect1 = r1; int wide = pdfRect1.size.width + pdfRect1.origin.x; int high = pdfRect1.size.height + pdfRect1.origin.y; CGContextRef ctxBuffer = NULL; CGColorSpaceRef colorSpace; UInt8* bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (wide * 4); bitmapByteCount = (bitmapBytesPerRow * high); colorSpace = CGColorSpaceCreateDeviceRGB(); bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { DebugLog (@"Memory not allocated!"); return; } ctxBuffer = CGBitmapContextCreate (bitmapData, wide, high, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); // if (ctxBuffer== NULL) { free (bitmapData); DebugLog (@"Context not created!"); return; } CGColorSpaceRelease( colorSpace ); //White out the current context CGContextSetRGBFillColor(ctxBuffer, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(ctxBuffer, CGContextGetClipBoundingBox(ctxBuffer)); CGContextDrawPDFPage(ctxBuffer, pageRef); //!!!This displays just fine to the context passed in from - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx. That is, I can see the PDf page rendered, so we know ctxBuffer was created correctly //However, if I view bitmapData in memory, it only shows as 0xFF (or whatever fill color I use) CGImageRef img = CGBitmapContextCreateImage(ctxBuffer); CGContextDrawImage(ctx, tiledLayer.frame, img); void *data = CGBitmapContextGetData (ctx); for (int i = 0; i < wide; i++) { for (int j = 0; j < high; j++) { //All of the bytes show as 0xFF (or whatever fill color I test with)?! int byteIndex = (j * 4) + i * 4; UInt8 red = bitmapData[byteIndex]; UInt8 green = bitmapData[byteIndex + 1]; UInt8 blue = bitmapData[byteIndex + 2]; UInt8 alpha = m_PixelBuf[byteIndex + 3]; } } I have also tried using CGDataProviderCopyData(CGImageGetDataProvider(img)) & CFDataGetBytePtr, but the results are the same?

    Read the article

  • Drawing a PDF Right-Side-Up in CGContext

    - by Carter Allen
    I'm overriding the drawRect: method in a custom UIView, and I'm doing some custom drawing. All was going well, until I needed to draw a PDF resource (a vector glyph, to be precise) into the context. First I retrieve the PDF from a file: NSURL *pdfURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CardKit.bundle/A.pdf"]]; CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDoc, 1); Then I create a box with the same dimensions as the loaded PDF: CGRect box = CGPDFPageGetBoxRect(pdfPage, kCGPDFArtBox); Then I save my graphics state, so that I don't screw anything up: CGContextSaveGState(context); And then I perform a scale+translate of the CTM, theoretically flipping the whole context: CGContextScaleCTM(context, 1.0, -1.0); CGContextTranslateCTM(context, 0.0, rect.size.height); I then scale the PDF so that it fits into the view properly: CGContextScaleCTM(context, rect.size.width/box.size.width, rect.size.height/box.size.height); And finally, I draw the PDF and restore the graphics state: CGContextDrawPDFPage(context, pdfPage); CGContextRestoreGState(context); The issue is that there is nothing visible drawn. All this code should theoretically draw the PDF glyph into the view, right? If I remove the scale+translate used to flip the context, it draws perfectly: it just draws upside-down. Any ideas?

    Read the article

  • CGContext rotation

    - by kasperjj
    I have a 100x100 pixel image that I want to draw at various angles rotated around the center of the image. The following code works, but rotates around the original origo of the coordinate system (upper left hand corner) and not the translated location. Thus the image is not rotated around itself but around the upper left corner of the screen. CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, -50, -50); CGContextRotateCTM (context, 0.3); CGContextTranslateCTM(context,768/2,1024/2); [image drawAtPoint:CGPointMake(0,0)]; I tried doing the same using CGAffineTransform, but got the same results.

    Read the article

  • Quartz Composer in iPhone UIView

    - by Peter Hajas
    Hi everyone, I am trying to embed a Quartz Composer document in an iPhone app. I know Quartz Composer support was added in iPhone OS 3.1 (at least, that's what Wikipedia says) but I can't find any good resources on how to do this. Do I use CGContext? Or are there more friendly ways to add a Quartz Composer composition? Thanks!

    Read the article

  • CGContextSetRBStrokeColor to replace, not add, for alpha?

    - by Peter Hajas
    I use CGContexts to allow the user to draw in my application, here's an example: CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), size); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),r,g,b,a); I want the user to have an "eraser" tool that actually erases - it can't draw white (that would add white to the image, which may not have a white background) or alpha (or else the stroke won't do anything). Is there a way to do this? Perhaps replacing contents of a CGContext or UIImage?

    Read the article

  • highlight scrolling text on iphone(about lyrics show )

    - by ????
    hi all, i'm in troubled show lyrics .i use uitextview show lyrics code snips IBOutlet UILabel *lrcshow; IBOutlet UITextView *showlrc; self.lrcshow.text = [lrcDictss objectForKey:[NSString stringWithFormat:@"%d",(int)self.player.currentTime]]; if (self.lrcshow.text!=nil) { NSRange selection = [self.showlrc.text rangeOfString:self.lrcshow.text]; if( selection.location != NSNotFound ) { showlrc.selectedRange = selection; } } lyrics line by line scrolling show,the problem is now playing(selectedRange) lyric is not highlight, i want this line highlight how can i code ? any suggestion?or use calayer ?cgcontext quartz core instead it? how can i code ? ps.use uitextview show is rigidly ,not smooth! lr style show pic url this is my app style: http://www.flickr.com/photos/53054715@N05/5359722887/ this is good style: flickr.com/photos/53054715@N05/5360345226/

    Read the article

  • CGBitmapContextCreate on the iPhone/iPad

    - by toastie
    Hello, I have a method that needs to parse through a bunch of large PNG images pixel by pixel (the PNGs are 600x600 pixels each). It seems to work great on the Simulator, but on the device (iPad), i get an EXC_BAD_ACCESS in some internal memory copying function. It seems the size is the culprit because if I try it on smaller images, everything seems to work. Here's the memory related meat of method below. + (CGRect) getAlphaBoundsForUImage: (UIImage*) image { CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *rawData = malloc(height * width * 4); memset(rawData,0,height * width * 4); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * width; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); /* non-memory related stuff */ free(rawData); When I run this on a bunch of images, it runs 12 times and then craps out, while on the simulator it runs no problem. Do you guys have any ideas?

    Read the article

  • UIView drawRect: when you draw a line, the rect area will be clear so the previous drawing is gone

    - by snakewa
    It is quite hard to tell so I upload an image to show my problem: http://i42.tinypic.com/2eezamo.jpg Basically in drawRect, I will draw the line from touchesMoved as finger touches and I will call "needsDisplayInRect" for redraw. But I found that the first line is done, the second line will clear the rect part, so some previouse drawing is gone. Here is my implementation: enter code here -(void) drawRect:(CGRect)rect{ //[super drawRect: rect]; CGContextRef context = UIGraphicsGetCurrentContext(); [self drawSquiggle:squiggle at:rect inContext:context]; } - (void)drawSquiggle:(Squiggle *)squiggle at:(CGRect) rect inContext:(CGContextRef)context { CGContextSetBlendMode(context, kCGBlendModeMultiply); UIColor *squiggleColor = squiggle.strokeColor; // get squiggle's color CGColorRef colorRef = [squiggleColor CGColor]; // get the CGColor CGContextSetStrokeColorWithColor(context, colorRef); NSMutableArray *points = [squiggle points]; // get points from squiggle // retrieve the NSValue object and store the value in firstPoint CGPoint firstPoint; // declare a CGPoint [[points objectAtIndex:0] getValue:&firstPoint]; // move to the point CGContextMoveToPoint(context, firstPoint.x, firstPoint.y); // draw a line from each point to the next in order for (int i = 1; i < [points count]; i++) { NSValue *value = [points objectAtIndex:i]; // get the next value CGPoint point; // declare a new point [value getValue:&point]; // store the value in point // draw a line to the new point CGContextAddLineToPoint(context, point.x, point.y); } // end for CGContextStrokePath(context); }

    Read the article

  • Simple iPhone drawing app with Quartz 2D

    - by Mr guy 4
    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 drawing rectangles. However, I just want a simple "freehand" mode like a lot of other iPhone applications have. The way I thought to do this was to create a CGMutablePath, and simply: CGMutablePathRef path; -(void)touchBegan { path = CGMutablePathCreate(); } -(void)touchMoved { CGPathMoveToPoint(path,NULL,x,y); CGPathAddLineToPoint(path,NULL,x,y); } -(void)drawRect:(CGContextRef)context { CGContextBeginPath(context); CGContextAddPath(context,path); CGContextStrokePath(context); } However, after drawing for more than 1 second, performance degrades miserably. I would just draw each line into the off-screen CGLayer, if it were not for variable opacity! The less-than-100% opacity causes dots to be left on the screen connecting the lines. I have looked at CGContextSetBlendingMode() but alas I cannot find an answer. Can anyone point me in the right direction? Other iPhone apps are able to do this with very good efficiency.

    Read the article

  • iPhone: CoreGraphics and memory management

    - by carloe
    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 would leak memory. -(UIImage *)pageAtIndex:(NSInteger)pageNumber withWidth:(CGFloat)width andHeight:(CGFloat)height { if((pageNumber>0) && (pageNumber<=pageCount)) { CGFloat scaleRatio; // multiplier by which the PDF Page will be scaled UIGraphicsBeginImageContext(CGSizeMake(width, height)); CGContextRef context = UIGraphicsGetCurrentContext(); CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber); CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox); //Figure out the orientation of the PDF page and set the scaleRatio accordingly if(pageRect.size.width/pageRect.size.height < 1.0) { scaleRatio = height/pageRect.size.height; } else { scaleRatio = width/pageRect.size.width; } //Calculate the offset to center the image CGFloat xOffset = 0.0; CGFloat yOffset = height; if(pageRect.size.width*scaleRatio<width) { xOffset = (width/2)-(pageRect.size.width*scaleRatio/2); } else { yOffset = height-((height/2)-(pageRect.size.height*scaleRatio/2)); } CGContextTranslateCTM(context, xOffset, yOffset); CGContextScaleCTM(context, 1.0, -1.0); CGContextSaveGState(context); CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFBleedBox, CGRectMake(0, 0, pageRect.size.width, pageRect.size.height), 0, true); pdfTransform = CGAffineTransformScale(pdfTransform, scaleRatio, scaleRatio); CGContextConcatCTM(context, pdfTransform); CGContextDrawPDFPage(context, page); UIImage *tempImage = [UIGraphicsGetImageFromCurrentImageContext() retain]; CGContextRestoreGState(context); UIGraphicsEndPDFContext(); UIGraphicsEndImageContext(); return tempImage; } return nil; }

    Read the article

  • Create new UIImage by adding shadow to existing UIImage

    - by Tom Irving
    I've taken a look at this question: http://stackoverflow.com/questions/962827/uiimage-shadow But the accepted answer didn't work for me. What I'm trying to do is take a UIImage and add a shadow to it, then return a whole new UIImage, shadow and all. This is what I'm trying: - (UIImage*)imageWithShadow { CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef shadowContext = CGBitmapContextCreate(NULL, self.size.width, self.size.height + 1, CGImageGetBitsPerComponent(self.CGImage), 0, colourSpace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colourSpace); CGContextSetShadow(shadowContext, CGSizeMake(0, -1), 1); CGContextDrawImage(shadowContext, CGRectMake(0, 0, self.size.width, self.size.height), self.CGImage); CGImageRef shadowedCGImage = CGBitmapContextCreateImage(shadowContext); CGContextRelease(shadowContext); UIImage * shadowedImage = [UIImage imageWithCGImage:shadowedCGImage]; CGImageRelease(shadowedCGImage); return shadowedImage; } The result is that I get exactly the same image as before I put it through this method. I am doing this the correct way, or is there something obvious I'm missing?

    Read the article

  • Core Graphics Rotating a Path

    - by Scott Langendyk
    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 = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 1.5); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); CGContextSetShadow(context, CGSizeMake(0, 1), 0); CGContextBeginPath(context); CGContextMoveToPoint(context, 13.5, 13.5); CGContextAddLineToPoint(context, 30.5, 13.5); CGContextAddLineToPoint(context, 30.5, 30.5); CGContextAddLineToPoint(context, 13.5, 30.5); CGContextAddLineToPoint(context, 13.5, 13.5); CGContextClosePath(context); CGContextMoveToPoint(context, 26.2, 13.5); CGContextAddLineToPoint(context, 26.2, 17.8); CGContextAddLineToPoint(context, 30.5, 17.8); CGContextMoveToPoint(context, 17.8, 13.5); CGContextAddLineToPoint(context, 17.8, 17.8); CGContextAddLineToPoint(context, 13.5, 17.8); CGContextMoveToPoint(context, 13.5, 26.2); CGContextAddLineToPoint(context, 17.8, 26.2); CGContextAddLineToPoint(context, 17.8, 30.5); CGContextStrokePath(context); CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 0, [UIColor clearColor].CGColor); CGContextFillRect(context, CGRectMake(26.2, 13.5, 4.3, 4.3)); CGContextFillRect(context, CGRectMake(13.5, 13.5, 4.3, 4.3)); CGContextFillRect(context, CGRectMake(13.5, 26.2, 4.3, 4.3)); CGContextRotateCTM(context, M_PI / 4); }

    Read the article

  • CALayer drawInContext vs addSublayer

    - by Michael
    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]; // this line is the problem [squaresLayer drawInContext:viewContext]; [self.layer addSublayer:imgLayer]; The other 2 by themselves draw correctly if I do them in that order. No matter where I try and put bottomLayer, it always prevents squaresLayer from drawing. The reason I need 3 layers is I intend to animate the colors in the background and custom layers. The top layer is just a graphical overlay.

    Read the article

1 2 3  | Next Page >