我是 Quartz 2D 和上下文世界的新手。为什么这段代码会崩溃?
NSMutableData* pdfData = [[NSMutableData alloc] initWithLength:1000];
CGRect bounds = (CGRectMake(100, 100, 100, 100));
NSDictionary* documentInfo = nil;
UIGraphicsBeginPDFContextToData (pdfData,
bounds,
documentInfo);
CGContextRef context = UIGraphicsGetCurrentContext();
NSLog (@"context: %@", context);
// Drawing lines with a white stroke color
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
// Draw a single line from left to right
CGContextMoveToPoint(context, 10.0, 30.0);
CGContextAddLineToPoint(context, 310.0, 30.0);
CGContextStrokePath(context);
[pdfData release];
代码在 CGContextStrokePath(context) 与 EXC_BAD_ACCESS 崩溃
谢谢你。