iOS图像处理之绘制直线

-(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();

}


你可能感兴趣的:(ios,图像处理,绘制直线)