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

    第一种

    //截屏
    - (UIImage *)ScreenCapture {
        //创建一个context
        //size画布的大小
        //opaque是否有透明度
        //scale画布的比率.
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
        //把当前的全部画面导入到栈顶context中并进行渲染
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        //从当前context中创建一个新图片
        UIImage * tempImage = UIGraphicsGetImageFromCurrentImageContext();
        //是当前的context出堆栈
        UIGraphicsEndImageContext();
        return tempImage;
    }

    第二种

    //截取任意位置,保存到相册
    - (void)SaveScreenCaptureToPhoneAlbum {
        
        UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage * tempImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsGetCurrentContext();
        CGImageRef tempRef = tempImage.CGImage;
        //截图区域
        CGRect tempRect = CGRectMake(2*self.view.frame.origin.x, 2*self.view.frame.origin.y - 15, 2 * self.view.frame.size.width, 2 * self.view.frame.size.height);
        CGImageRef tempImageRef = CGImageCreateWithImageInRect(tempRef, tempRect);
        UIImage * sendImage = [[UIImage alloc] initWithCGImage:tempImageRef];
        //保存到相册
        UIImageWriteToSavedPhotosAlbum(sendImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }

    //保存到相册
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
        if (error == nil) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
        }else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败,你的设置里的隐私设置,可能拒绝了,XXXXX访问你的照片" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
        }
    }

  • 相关阅读:
    chrome输入框记住密码导致背景黄色的解决方案
    死活要居中(转载)
    Google HTML/CSS/JS代码风格指南
    CSS的inherit与auto使用分析
    photoshop中rgb与索引模式的区别
    placeholder调整颜色
    你应该了解的5个JavaScript调试技巧
    HTML TAG FROM MDN
    apple iphone 3gs 有锁机 刷机 越狱 解锁 全教程(报错3194,3014,1600,短信发不出去等问题可参考)
    史上最全的CSS hack方式一览
  • 原文地址:https://www.cnblogs.com/yujidewu/p/5780219.html
Copyright © 2011-2022 走看看