您的位置:首页 > 移动开发 > IOS开发

iOS图像处理之绘制直线

2016-05-12 11:24 477 查看
-(void)drawLine:(CGPoint)fromPnt toPoint:(CGPoint)toPnt{

float xScale = theImageView.image.size.width/theImageView.frame.size.width;
float yScale = theImageView.image.size.height/theImageView.frame.size.height;

UIGraphicsBeginImageContext(theImageView.image.size);
[theImageView.image drawInRect:CGRectMake(0, 0, theImageView.image.size.width, theImageView.image.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0*[self returnMax:xScale withNumber:yScale]);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), fromPnt.x*xScale, fromPnt.y*yScale);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), toPnt.x*xScale, toPnt.y*yScale);
CGContextStrokePath(UIGraphicsGetCurrentContext());
theImageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息