美文网首页
纯色图片

纯色图片

作者: 红红宝宝 | 来源:发表于2020-08-18 11:04 被阅读0次

  UIImage *img = [self scaleToSize:[self getImageWithColor:[UIColor clearColor]] size:CGSizeMake(0.5, 0.5)];

//缩放图片
- (UIImage*)scaleToSize:(UIImage*)imgsize:(CGSize)size {

    // 创建一个bitmap的context

    // 并把它设置成为当前正在使用的context

    UIGraphicsBeginImageContext(size);

    // 绘制改变大小的图片

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

    // 从当前context中创建一个改变大小后的图片

    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    // 使当前的context出堆栈

    UIGraphicsEndImageContext();

    // 返回新的改变大小后的图片

    returnscaledImage;

}

//纯色图片

- (UIImage*)getImageWithColor:(UIColor*)color {

    CGRectrect =CGRectMake(0.0f,0.0f,1.0f,1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);

    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimage;

}

相关文章

网友评论

      本文标题:纯色图片

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