我想在iOS上創建簡單的圖形編輯器,其中我使用位圖圖形上下文和bezier路徑將行轉換爲圖片。如何在簡單的圖形編輯器中實現橡皮擦?
我沒有找到方法來創建一個橡皮擦。
你有什麼想法嗎?
- (void)drawRect:(CGRect)rect {
[[UIColor blackColor] setStroke];
CGContextRef aRef = UIGraphicsGetCurrentContext();
aPath.lineWidth = 5;
[aPath stroke];
[[[UIColor blackColor] colorWithAlphaComponent:0] setStroke];
bPath.lineWidth = 5;
[bPath stroke];
movesss= CGBitmapContextCreateImage(aRef);
if (movesss==NULL) {
NSLog(@"null =(");
}
}
-(void)moveTo:(CGPoint)pos {
if(del){
[bPath moveToPoint:pos];
}
else{
[aPath moveToPoint:pos];
}
}
-(void)cret{
aPath=[[UIBezierPath bezierPath] retain];
bPath=[[UIBezierPath bezierPath] retain];
del=NO;
}
-(void)lineTo:(CGPoint)pos {
if(del){
[bPath addLineToPoint:pos];
}
else{
[aPath addLineToPoint:pos];
}
[self setNeedsDisplay];
}
-(void)imgf{
UIImage *imageToSave=[[UIImage imageWithCGImage:movesss] retain];
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil);
UIImageView *trew=[[UIImageView alloc] initWithFrame:[self frame]];
[trew setBackgroundColor:[UIColor greenColor]];
[trew setImage:imageToSave];
[self addSubview:trew];
}
-(void)swittch{
del=!del;
}
這裏有什麼錯?
我按照你的意見,但它不起作用:線條仍然是黑色的。 – Riddick
謝謝你的鏈接。我的背景色是透明的。我只需要像這樣改變混合模式:CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeCopy); – Riddick