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

    1.普通的截图办法,在View上面截图

    /**
     *  截图代码
     *
     *  @param view 需要截图的view
     *  @param rect 需要截取的区域
     *
     *  @return 返回截取的对象
     */
    + (UIImage *)viewSnapshot:(UIView *)view withInRect:(CGRect)rect
    {
        
        UIGraphicsBeginImageContext(view.bounds.size);
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,rect);
        image = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
        return image;
    }

    2.截取UIScrollView的ContentSize的全部区域,包括未显示的部分,将UIScrollView传递进去

    /**
     *  UIScrollView从顶截到底
     *
     *  @param scrollView 需要呗截图的UIScrollView
     *
     *  @return 返回UIScrollView的ContentSize的截图
     */
    + (UIImage *)screenShot:(UIScrollView *)scrollView{
        UIImage *image = nil;
        UIGraphicsBeginImageContext(scrollView.contentSize);
        {
            CGPoint savedContentOffset = scrollView.contentOffset;
            CGRect savedFrame = scrollView.frame;
            scrollView.contentOffset = CGPointZero;
            scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
            [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
            image = UIGraphicsGetImageFromCurrentImageContext();
            scrollView.contentOffset = savedContentOffset;
            scrollView.frame = savedFrame;
        }
        UIGraphicsEndImageContext();
        
        if (image != nil) {
            NSLog(@"截图成功!");
        }
        
        return image;
    }
  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    C语言I学期总结
  • 原文地址:https://www.cnblogs.com/wobuyayi/p/5524126.html
Copyright © 2011-2022 走看看