UIImage 图片处理:截图,缩放,设定大小,存储,web应用系统开发

1. 从UIView中获取图像相当于窗口截屏。

(ios提供全局的全屏截屏函数UIGetScreenView(). 如果需要特定区域的图像,可以crop一下)

  1. CGImageRef screen = UIGetScreenImage();

  2. UIImage* image = [UIImage imageWithCGImage:screen];

2. 对于特定UIView的截屏。

(可以把当前View的layer,输出到一个ImageContext中,然后利用这个ImageContext得到UIImage)

  1. -(UIImage*)captureView: (UIView *)theView

  2. {

  3. CGRect rect = theView.frame;

  4. UIGraphicsBeginImageContext(rect.size);

  5. CGContextRef context =UIGraphicsGetCurrentContext();

  6. [theView.layer renderInContext:context];

  7. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

  8. UIGraphicsEndImageContext();

  1. return img;

  2. }

3. 如果需要裁剪指定区域。

(可以path & clip,以下例子是建一个200x200的图像上下文,再截取出左上角)

  1. UIGraphicsBeginImageContext(CGMakeSize(200,200));

  2. CGContextRefcontext=UIGraphicsGetCurrentContext();

  3. UIGraphicsPushContext(context);

  4. // …把图写到context中,省略[indent]CGContextBeginPath();

  5. CGContextAddRect(CGMakeRect(0,0,100,100));

  6. CGContextClosePath

  • 26
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值