qt怎么将按钮设为图片
312
2022-09-14
ios Image裁剪成圆形 圆形头像
1、通过image mask来操作,需要添加mask目标图片。
//通过image mask来操作,需要添加mask目标图片。
UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 300, 100, 100)];
UIGraphicsBeginImageContext(icon.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextFillRect(ctx, CGRectMake(0, 0, icon.bounds.size.width, icon.bounds.size.height));
UIGraphicsEndImageContext();
UIImage *image = [UIImage imageNamed:@"main.jpg"];
UIImage *roundCorner = [UIImage imageNamed:@"corner_no_clear.png"];
icon.image = image;
CALayer* roundCornerLayer = [CALayer layer];
roundCornerLayer.frame = icon.bounds;
roundCornerLayer.contents = (id)[roundCorner CGImage];
[[icon layer] setMask:roundCornerLayer];
[self.view addSubview:icon];
2、通过imageview的layer来操作
//通过imageview的layer来操作
UIImage *main = [UIImage imageNamed:@"main.jpg"];
UIImage *corner_no_shadow = [UIImage imageNamed:@"corner_no_shadow.png"];
UIImageView *img0 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 100, 100)];
img0.backgroundColor = [UIColor redColor];
img0.image = main;
img0.layer.masksToBounds = YES;
img0.layer.cornerRadius = 50;
[self.view addSubview:img0];
3、能过代码对画布裁剪成圆形–》然后再将原始图像画出来–》
//能过代码对画布裁剪成圆形–》然后再将原始图像画出来–》
UIImage *main = [UIImage imageNamed:@"main.jpg"];
UIImage *corner_no_shadow = [UIImage imageNamed:@"corner_no_shadow.png"];
UIImage *ii = [main circleImage:main withParam:0];
UIImageView *img1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, 100, 100)];
img1.image = ii;
[self.view addSubview:img1];
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~