• 完美解决scrollView 截屏图片模糊


    UIGraphicsBeginImageContext

     

    首先说明一下UIGraphicsBeginImageContextWithOptions 和UIGraphicsBeginImageContext区别:

     

    1: UIGraphicsBeginImageContext(CGSize size)

    参数size为新创建的位图上下文的大小。它同时是由UIGraphicsGetImageFromCurrentImageContext函数返回的图形大小。

    该函数的功能同UIGraphicsBeginImageContextWithOptions的功能相同,相当与UIGraphicsBeginImageContextWithOptions的opaque参数为NO,scale因子为1.0

     

     

    2 UIGraphicsBeginImageContextWithOptions

     

    函数原型为:

    void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);

    size——同UIGraphicsBeginImageContext

    opaque—透明开关,如果图形完全不用透明,设置为YES以优化位图的存储。

    scale—–缩放因子

    特别说明,当缩放因子为0.0时候,图片不模糊

    //截屏

    - (UIImage *)CaptureScrollView:(UIScrollView *)scrollView{

        UIImage* image = nil;

    //    UIGraphicsBeginImageContext(scrollView.contentSize);  默认

        UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, NO, 0.0);

        {

            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) {

            return image;

        }

        return nil;

    }

  • 相关阅读:
    Ahoi2013 作业
    bzoj 2502 清理雪道 (有源汇上下界最小流)
    zoj 3229 Shoot the Bullet(有源汇上下界最大流)
    TCP协议和socket API 学习笔记
    http、TCP/IP协议与socket之间的区别
    ios多线程和进程的区别(转载)
    iOS进程间通信之CFMessagePort
    功能强大的Xcode辅助工具Faux Pas:帮你找到各种隐形的bug
    [深入浅出Cocoa]iOS程序性能优化
    IOS之禁用UIWebView的默认交互行为
  • 原文地址:https://www.cnblogs.com/haijieFeng/p/5568135.html
Copyright © 2020-2023  润新知