zoukankan      html  css  js  c++  java
  • ios编程:iPhone Howto:给UIView拍照

    ios编程:iPhone How-to:给UIView拍照

    时间:2011-04-22 csdn博客 林家男孩
     

    基本原理就是主要将UIView的layer描绘到图形上下文。UIView全局拍照和局域拍照的代码如下:

    1 UIView全局拍照

    - (UIImage *) screenImage:(UIView *)view {
    UIImage *screenImage;
    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
    }

    2 UIView局域拍照

    - (UIImage *) screenImage:(UIView *)view rect:(CGRect)rect {
    CGPoint pt = rect.origin;
    UIImage *screenImage;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextConcatCTM(context,
    CGAffineTransformMakeTranslation(-(int)pt.x, -(int)pt.y));
    [view.layer renderInContext:context];
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
    }

    来源:http://blog.csdn.net/lbj05/archive/2011/04/02/6297209.aspx

  • 相关阅读:
    树莓派GPIO点亮第一个led
    hexo博客域名重复提交问题
    python与arduino串口通讯对接opencv实现智能物品分拣
    python生成excel文件
    python的机器学习之路
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
    第二阶段任务认领
    构建之法3
  • 原文地址:https://www.cnblogs.com/iphone520/p/2471439.html
Copyright © 2011-2022 走看看