Rap*_*eta 4 cgcontext cgbitmapcontextcreate ios4
我已经在这几个小时了,甚至不知道如何调试这个错误.也许有一位SO专家知道发生了什么.
- (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.x, -cropRect.origin.y);
subsetWidth = cropRect.size.width * scale;
subsetHeight = cropRect.size.height * scale;
subsetBytesPerRow = ((subsetWidth + 0xf) >> 4) << 4;
subsetData = (unsigned char *)malloc(subsetBytesPerRow * subsetHeight);
CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef ctx = CGBitmapContextCreate(subsetData, subsetWidth, subsetHeight, 8, subsetBytesPerRow, grayColorSpace, kCGImageAlphaNone);
CGColorSpaceRelease(grayColorSpace);
CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
CGContextSetAllowsAntialiasing(ctx, false);
CGContextTranslateCTM(ctx, 0.0, subsetHeight);
CGContextScaleCTM(ctx, 1.0, -1.0);
UIGraphicsPushContext(ctx);
CGRect rect = CGRectMake(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
[image drawInRect:rect];
UIGraphicsPopContext();
CGContextFlush(ctx);
CGImageRef subsetImageRef = CGBitmapContextCreateImage(ctx);
self.subsetImage = [UIImage imageWithCGImage:subsetImageRef];
CGImageRelease(subsetImageRef);
CGContextRelease(ctx);
Run Code Online (Sandbox Code Playgroud)
}
这些是我调用此方法后出现的错误
<Error>: CGContextSetInterpolationQuality: invalid context 0x0
<Error>: CGContextSetAllowsAntialiasing: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetBlendMode: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextFlush: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我发生了什么事吗?提前致谢.
写下绘图代码drawRect.当你想绘制,调用时[self setNeedsDisplay],调用你的实现drawRect.如果您是在视图控制器中绘图,请[self.view setNeedsDisplay]改为调用.例如:
-(void)drawRect:(CGRect)rect {
CGRect currentRect = CGRectMake(50,50,20,20);
UIColor *currentColor = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextSetFillColorWithColor(context, currentColor.CGColor);
CGContextAddEllipseInRect(context, currentRect);
CGContextDrawPath(context, kCGPathFillStroke);
}
- (void)nowIWantToDraw {
[self.view setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19040 次 |
| 最近记录: |