zoukankan      html  css  js  c++  java
  • 完美解决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;

    }

  • 相关阅读:
    二叉搜索树与双向链表
    复杂链表的复制
    二叉树中和为某一值的路径
    二叉树的后序遍历
    从上往下打印二叉树
    栈的压入,弹出序列
    包含min函数的栈
    JS基础知识
    有序列表、无序列表、网页的格式和布局
    样式表(宽度和高度、背景字体、对齐方式边界与边框)
  • 原文地址:https://www.cnblogs.com/haijieFeng/p/5568135.html
Copyright © 2011-2022 走看看