我想在 iOS 上创建简单的图形编辑器,在其中我使用位图图形上下文和贝塞尔路径将线条转换为图片。
我没有找到创建橡皮擦的方法。
你有什么想法?
- (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;
}
这里有什么问题?