美文网首页
绘制图片代码

绘制图片代码

作者: 东引瓯越 | 来源:发表于2016-08-25 09:20 被阅读59次
    -(UIImage*)composeStereogramLeft:(UIImage *)leftImage right:(UIImage *)rightImage
    {
        float w = leftImage.size.width;
        float h = leftImage.size.height;
        UIGraphicsBeginImageContext(CGSizeMake(w * 2.0, h + 32.0));
        [leftImage drawAtPoint:CGPointMake(0.0, 32.0)];
        [rightImage drawAtPoint:CGPointMake(w, 32.0)];
        float leftCircleX = (w / 2.0) - 8.0;
        float rightCircleX = leftCircleX + w;
        float circleY = 8.0;
        [[UIColor blackColor] setFill];
        UIRectFill(CGRectMake(0.0, 0.0, w * 2.0, 32.0));
    
        [[UIColor whiteColor] setFill];
        CGRect leftRect = CGRectMake(leftCircleX, circleY, 16.0, 16.0);
        CGRect rightRect = CGRectMake(rightCircleX, circleY, 16.0, 16.0);
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:leftRect];
        [path appendPath:[UIBezierPath bezierPathWithOvalInRect:rightRect]];
        [path fill];
        UIImage *savedImg = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return savedImg;
    }
        
    

    相关文章

      网友评论

          本文标题:绘制图片代码

          本文链接:https://www.haomeiwen.com/subject/abnosttx.html