• 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;

        }

    }

  • 相关阅读:
    Python中怎么使用(冒泡排序)?
    Python中怎么定义与调用(函数)
    简易购物商城(1.0)版本
    非空即真 和 切片 处理方式
    python模块-random
    内置函数
    多维数组
    函数扩展
    文件操作扩展2
    文件操作扩展
  • 原文地址:https://www.cnblogs.com/chenjohney/p/3216232.html
Copyright © 2020-2023  润新知