2013-09-20 1 views
0

Я рисую часть изображения UIButtons, после нажатия кнопки очистки. Мне нужно сначала сбросить изображение кнопок (удалить рисунок). Я установил образ UIButton с свойством setImage, но он не работал. Как очистить рисунок от изображения? Я использую следующий код для рисования на UIImage,очистить рисунок от UIImage?

UIImageView *imgView =[[UIImageView alloc]init];  
    UIGraphicsBeginImageContext(self.frame.size); 
    [imgView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), self.drawingWidth); 


    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),lipColor.CGColor); 
    CGContextSetAlpha(UIGraphicsGetCurrentContext(), self.currntAlpha); 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    CGContextFlush(UIGraphicsGetCurrentContext()); 
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeOverlay); 
    imgView.image = UIGraphicsGetImageFromCurrentImageContext(); 
    imgView.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);// Set frame for imageView 
    [self.imageView addSubview:imgView]; 
    UIGraphicsEndImageContext(); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextClearRect(context, self.bounds); 
    imgView.layer.shadowOffset = CGSizeZero; 
    imgView.layer.masksToBounds = NO;   
    imgView.alpha=0.05; 
    lastPoint=currentPoint; 
    self.layer.shadowOpacity=0.01; 

Любая помощь очень ценится !!!!!!

+0

Любая помощь очень ценится !!!!!! – Arunkumar

ответ

1

Простое решение - сохранить исходное изображение в начале и когда вы хотите, чтобы стереть линии просто сделать:

self.image = savedImage 

Однако гораздо лучшее решение (с более высокой производительностью) было бы не меняя изображение на все, но имеют прозрачный вид над UIImageView и рисуют внутри него. Рисунок также может быть намного проще (например, с буфером CGImageRef вместо создания контекста изображения каждый раз на UIGraphicsBeginImageContext).

+0

Спасибо за ваш ответ. Я попробую это. – Arunkumar