zoukankan      html  css  js  c++  java
  • iOS UIView 截屏

    h文件:

    @interface UIView (Screenshot)

    //目前最完善

    - (UIImage*) screenshotAtFrame:(CGRect)r;

    @end

     

     

     

    m文件:

    //目前最完善

    - (UIImage*) screenshotAtFrame:(CGRect)r

    {

        float scale = [UIScreen mainScreen].scale*2.0;

        UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, scale);

        [self.layer renderInContext:UIGraphicsGetCurrentContext()];

        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        

        if (CGRectEqualToRect(self.bounds, r)){

            return theImage;

        }else{

            CGImageRef imageRef = theImage.CGImage;

            r.origin.x = r.origin.x * scale;

            r.origin.y = r.origin.y * scale;

            r.size.height = r.size.height * scale;

            r.size.width = r.size.width * scale;

            CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, r);

            UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];

            return  sendImage;

        }

    }

  • 相关阅读:
    一位区域销售经理百条经验手记
    PAIP.FLEX与JAVA数据对应关系.txt
    转:java生成EXCEL表格(POI vs JXL)
    逆向分析工具介绍
    applet与SERLET交互...
    AT命令集(
    关于WINDOWS超级终端的使用来调试MODEM,串口.
    poj1331
    poj1338
    poj1325
  • 原文地址:https://www.cnblogs.com/chenjohney/p/3216232.html
Copyright © 2011-2022 走看看