从view上截取部分图片

来源:互联网 发布:中国移动数据家庭联盟 编辑:程序博客网 时间:2024/06/01 09:55

代码片中bg是一个imageView,

UIGraphicsBeginImageContextWithOptions(bg.frame.size, YES, 1.0);//yes表示透明,1.0表示不进行缩放    [bg.layer renderInContext:UIGraphicsGetCurrentContext()];    UIImage *bgImg = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    CGImageRef imageRef = bgImg.CGImage;    CGImageRef shotRef = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, bg.frame.size.height - 64, [UIScreen mainScreen].bounds.size.width, 64));    UIImage *shotImage = [[UIImage alloc] initWithCGImage:shotRef];//最后获得的图片,size高为64    CGImageRelease(shotRef);
0 0
原创粉丝点击