前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >iOS使用代码截图

iOS使用代码截图

原创
作者头像
用户8983410
修改2021-11-01 09:11:55
修改2021-11-01 09:11:55
1K00
代码可运行
举报
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
复制
// 从view上截图  
- (UIImage *)getImage {  

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(150, 150), NO, 1.0);  //NO,YES 控制是否透明  
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];  
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    // 生成后的image  

    return image;  
}  

// 根据给定得图片,从其指定区域截取一张新得图片  
-(UIImage *)getImageFromImage{  
    //大图bigImage  
    //定义myImageRect,截图的区域  
    CGRect myImageRect = CGRectMake(70, 10, 150, 150);  
    UIImage* bigImage= [UIImage imageNamed:@"mm.jpg"];  
    CGImageRef imageRef = bigImage.CGImage;  
    CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);  
    CGSize size;  
    size.width = 150;  
    size.height = 150;  
    UIGraphicsBeginImageContext(size);  
    CGContextRef context = UIGraphicsGetCurrentContext();  
    CGContextDrawImage(context, myImageRect, subImageRef);  
    UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];  
    UIGraphicsEndImageContext();  
    return smallImage;  
} 


</pre> 

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档