cgcontext

Drawing a dashed line with CGContextSetLineDash

流过昼夜 提交于 2019-12-01 01:49:06
问题 I'm trying to draw a dashed line with CGContextSetLineDash . Here's my code: float dashPhase = 0.0; float dashLengths[] = {30, 30}; CGContextSetLineDash(context, dashPhase, dashLengths, 20.0); self.previousPoint2 = self.previousPoint1; self.previousPoint1 = previous; self.currentPoint = current; self.mid1 = [self pointBetween:self.previousPoint1 andPoint:self.previousPoint2]; self.mid2 = [self pointBetween:self.currentPoint andPoint:self.previousPoint1]; UIBezierPath* newPath = [UIBezierPath

Using CGContext to draw line

假如想象 提交于 2019-12-01 01:36:54
问题 I wanted to draw a line using CGContext and what I have so far is: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); CGContextSetLineWidth(context, 1.0f); CGContextMoveToPoint(context, 10, 10); CGContextAddLineToPoint(context, 100, 50); CGContextStrokePath(context); It always draws from the top left corner to the top bottom right corner. How can I adjust the start and end origin of this line? How do I adjust the

Crazy rounded rect UIBezierPath behavior on iOS 7. What is the deal?

和自甴很熟 提交于 2019-11-30 22:14:34
The simple UIView below draws a rounded rectangle. When I pass a corner radius of 65 or below it rounds correctly, but 66 and above and it generates a perfect circle! What is going on here? It should only show a circle when the corner radius is equal to 1/2 the frame width, but it seems that it is drawing a circle when the radius is about 1/3rd, no matter what the size of the view is. This behavior appears on iOS 7. On iOS 6 I get expected behavior. #import "ViewController.h" @interface MyView : UIView @end @implementation MyView -(void)drawRect:(CGRect)rect { UIBezierPath *path =

OpenGL ES; rendering texture created from CGBitmapContext

早过忘川 提交于 2019-11-30 19:46:52
问题 I am executing the following, which I have derived from a few different tutorials (Just a single render pass, initialisation code not shown but works fine for untextured primitives): glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0, xSize, 0, ySize, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_ONE, GL_SRC_COLOR); GLuint texture[1]; glGenTextures(1, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]);

PDF Generation From UIScrollView + iphone

有些话、适合烂在心里 提交于 2019-11-30 15:43:09
I want to generate a pdf of UIScrollView whose content size is near about 320*2000. If I use current graphic image context to capture the scroll view layer, then it only captures the visible part of the scroll view not the whole layer of that scroll view. I am using the below code: -(void)CreatePdf:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *saveDirectory = [paths objectAtIndex:0]; NSString *saveFileName = @"myPDF.pdf"; [self writePDFAma]; CGRect arect=CGRectMake(0, 0, 768, 1024); CreatePDFFileAma(arect, nil); } -

Saving and restoring CGContext

◇◆丶佛笑我妖孽 提交于 2019-11-30 13:04:15
I'm trying to save and restore a CGContext to avoid doing heavy drawing computations for a second time and I'm getting the error <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) { CGContextRestoreGState(context); //scale context return; } initialized = YES; //heavy drawing computation and drawing CGContextSaveGState(context); } Brad Larson I think you might be misinterpreting what CGContextSaveGState() and CGContextRestoreGState() do.

CGContext line drawing: CGContextFillPath not working?

牧云@^-^@ 提交于 2019-11-30 11:46:06
Anyone have any idea why CGContextFillPath won't work in the code snippet below? I'm using the following code to draw to a UIImageView. It's stroking the path correctly, but ignoring CGContextFillPath. UIGraphicsBeginImageContext(self.frame.size); [drawingView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1

drawInRect: losing Quality of Image resolution

倾然丶 夕夏残阳落幕 提交于 2019-11-30 11:16:03
I am trying to erase image using following code CGColorRef strokeColor = [UIColor whiteColor].CGColor; UIGraphicsBeginImageContext(imgForeground.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [imgForeground.image drawInRect:CGRectMake(0, 0, imgForeground.frame.size.width, imgForeground.frame.size.height)]; CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, 10); CGContextSetStrokeColorWithColor(context, strokeColor); CGContextSetBlendMode(context, kCGBlendModeClear); CGContextBeginPath(context); CGContextMoveToPoint(context, lastPoint.x, lastPoint

Drawing into CGImageRef

情到浓时终转凉″ 提交于 2019-11-30 09:38:36
I want to create a CGImageRef and draw points to it. What context to use to create an empty CGImageRef and be able to draw onto it. CGContextRef or CGBitmapContextRef? If you can provide code to create an empty CGImageRef image and draw to it I would appreciate. #define HIRESDEVICE (((int)rintf([[[UIScreen mainScreen] currentMode] size].width/[[UIScreen mainScreen] bounds].size.width )>1)) - (CGImageRef) blerg { CGFloat imageScale = (CGFloat)1.0; CGFloat width = (CGFloat)180.0; CGFloat height = (CGFloat)180.0; if ( HIRESDEVICE ) { imageScale = (CGFloat)2.0; } // Create a bitmap graphics

Crazy rounded rect UIBezierPath behavior on iOS 7. What is the deal?

主宰稳场 提交于 2019-11-30 05:33:30
问题 The simple UIView below draws a rounded rectangle. When I pass a corner radius of 65 or below it rounds correctly, but 66 and above and it generates a perfect circle! What is going on here? It should only show a circle when the corner radius is equal to 1/2 the frame width, but it seems that it is drawing a circle when the radius is about 1/3rd, no matter what the size of the view is. This behavior appears on iOS 7. On iOS 6 I get expected behavior. #import "ViewController.h" @interface