我想在drawRect中保留以前的繪圖(系統每次清除它),而且似乎要使用位圖上下文並且足夠肯定,這個作品除了現在我的顏色消失以外,只剩下黑色和白色。我的顏色位圖在drawRect(iPhone)中只有黑色和白色
這裏是我的 「靜態」 的背景下
-(id)initWithCoder:(NSCoder *)aDecoder {
...
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
contextRef = CGBitmapContextCreate(NULL,
320,
640,
8,
320*4,
colorSpace,
kCGImageAlphaPremultipliedLast);
...
}
,這裏是我的更換背景:
-(void)drawRect:(CGRect)rect {
myDrawRoutine();
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, rect, CGBitmapContextCreateImage(contextRef));
}
這是平局常規的膽量:
...
// CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRef context = contextRef;
if(!(context))
return;
CGContextSetFillColor(context, CGColorGetComponents([co CGColor]));
CGContextSetStrokeColor(context, CGColorGetComponents([co CGColor]));
CGContextFillEllipseInRect(context, CGRectMake((*i)->x,
(*i)->y,
(*i)->diam,
(*i)->diam));
...
}
對於這種設置,CGLayer比CGBitmapContext更適合於緩存你的darwings。 – tonklon 2010-07-31 10:30:03