绘图

这篇博客介绍了如何在绘图过程中运用颜色填充和利用图片作为素材进行创作,包括使用颜色绘制完整图片以及将图片融入到画布上的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


绘图

使用颜色绘制一张图片

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(50,50),YES,0); // 创建一个bitmap上下文
CGContextRef context =UIGraphicsGetCurrentContext(); //获取bitmap上下文
    [[UIColorcolorWithRed:250/255.0green:250/255.0blue:250/255.0alpha:1]set];

CGContextFillRect(context,CGRectMake(0,0,50,50)); //绘图    
   UIImage *image =UIGraphicsGetImageFromCurrentImageContext();//拿到图片
    UIGraphicsEndImageContext(); // 关闭上下文
    // 保存图片
    NSData *data =UIImageJPEGRepresentation(image,1);
    [data writeToFile:@""atomically:YES];


使用图片绘制图片

    UIImage *image = [UIImageimageNamed:@"2.jpg"];
    UIGraphicsBeginImageContextWithOptions(image.size,YES,0);
    [image drawAtPoint:CGPointMake(0,0)];
    UIImage *image1 = [UIImageimageNamed:@"vip_ic_reason_1"];
    [image1 drawAtPoint:CGPointMake(200,200)];
    NSString *str =@"我是超人";
    [str drawAtPoint:CGPointMake(120,120)withAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:14]}];
    UIImage *image11 =UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    NSData *data =UIImageJPEGRepresentation(image11,1);
    [data writeToFile:@"/Users/zhoupengju/Desktop/test@.png"atomically:YES];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值