美文网首页
iOS:图片URL转UIImage;UIColor转UIImag

iOS:图片URL转UIImage;UIColor转UIImag

作者: Minnie_Liu | 来源:发表于2022-07-26 15:02 被阅读0次

    //url->UIImage

    -(UIImage *) getImageFromURL:(NSString *)fileURL {

        UIImage*result;

        NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];

        result = [UIImage imageWithData:data];

        return result;

    }

    //  颜色转换为背景图片UIColor->UIImage

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

        CGRect rect =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();

        return image;

    }

    相关文章

      网友评论

          本文标题:iOS:图片URL转UIImage;UIColor转UIImag

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