Quartz的学习2

//加载图片

UIImage*image=[UIImage imageNamed:@"angry_00.jpg"];

//上下文 : 基于位图image,所有的东西需要绘制到一张新的图片上去
//1.创建一个基于位图的上下文(开启一个基于位图的上下文)
//size : 新图片的尺寸
//opaque : 不透明度
//创建一张新的image,也就是新的UIImage对象

UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);

//2.画背景

[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];

//3.画右下角水印图片

UIImage*waterImage=[UIImage imageNamed:@"1.png"];

//设置位置和大小以及显示模式和透明度

[waterImage drawInRect:CGRectMake(image.size.width/2-80, image.size.height/2+80, waterImage.size.width*0.4, waterImage.size.height*0.5)blendMode:kCGBlendModeNormal alpha:0.4];

//4.从上下文中取得制作完毕的UIImange对象

UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext();

//5.结束图片上下文

UIGraphicsEndImageContext();

//6.加载ImageView

UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake( self.frame.size.width-200,self.frame.size.height-300, 200, 300)];

imageView.image=newImage;

[self addSubview:imageView];

//7.将image对象压缩为PNG格式的二进制对象.

NSData *data = UIImagePNGRepresentation(newImage);

//8.写入文件
// ......

}

//4.绘制饼状图1.0

-(void)drawBing{

CGContextRef context=UIGraphicsGetCurrentContext();

float a=0;

for (float i=1; i<21; i++) {

    CGContextAddArc(context, self.frame.size.width/2, self.frame.size.height/2-60, 60,a/20*2*3.14,i/20*2*3.14, 0);

    CGContextAddLineToPoint(context, self.frame.size.width/2, self.frame.size.height/2-60);

    CGContextClosePath(context);

    [[self randomColor] setFill];

    CGContextDrawPath(context, kCGPathFillStroke);

    a=i;
}

}

//绘制饼状图1.1

-(void)drawPiont{

NSArray *data = @[ @25, @15, @10 , @17 , @3, @10, @20];

//  设置圆心

CGPoint center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2+100);

//  设置半径

CGFloat r = 60;

//  起始弧度  和  结束弧度

CGFloat start = 0;

CGFloat end = 0;

for (NSInteger i = 0; i <data.count; i++) {

    //  结束弧度

    end = [data[i]floatValue ] / 100 * 2 * 3.14 + start ;

    //  创建路径

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:r startAngle:start endAngle:end clockwise:YES];

    //  连接圆心

    [path addLineToPoint:center];

    //  设置饼的颜色

    [[self randomColor] set];

    //   渲染

    [path fill];

    start = end;
}

}

// 随机的颜色

-(UIColor *)randomColor{

UIColor *color = [UIColor colorWithRed:(arc4random_uniform(256)/255.0) green:(arc4random_uniform(256)/255.0) blue:(arc4random_uniform(256)/255.0) alpha:1];

return color;

}

//5.通过传值来绘制圆

-(void)drawCircleWithValue:(float )Number{

[self setNeedsDisplay];

CGContextRef context=UIGraphicsGetCurrentContext();

CGContextAddArc(context, self.frame.size.width/2, self.frame.size.height/2-60, 100,3.14,Number/10*2*3.15+3.14,0);

CGContextSetLineWidth(context, 5);

[[self randomColor] set];

//圆环

//CGContextStrokePath(context);

//扇形图

CGContextAddLineToPoint(context, self.frame.size.width/2, self.frame.size.height/2-60);

CGContextClosePath(context);

CGContextFillPath(context);
 

转载于:https://my.oschina.net/u/2893301/blog/737979

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值