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;

        }

    }

  • 相关阅读:
    记录C#-WPF线程中如何修改值
    记录MySql错误消息
    记录C#-WPF布局面板
    记录TortoiseGit=>https请求/ssh请求配置
    工具-Xmind常用快捷键/使用
    记录C#泛型
    记录console的使用
    记录Flex布局的属性
    Spark的Monitoring
    HBase安装学习
  • 原文地址:https://www.cnblogs.com/chenjohney/p/3216232.html
Copyright © 2011-2022 走看看