zoukankan      html  css  js  c++  java
  • 截图代码

    返回的图片是UIImage,截图区域要乘以2,因为是 CGImageRef 截图,按像素来得(应该是retina屏的原因)

    - (UIImage *)snapshotTakeCarView:(UIScrollView *)view count:(int)count
    {
        UIImage* image = nil;
        
        UIGraphicsBeginImageContextWithOptions(view.contentSize, YES, 0);
        {
            CGPoint savedContentOffset = view.contentOffset;
            CGRect savedFrame = view.frame;
            
            view.contentOffset = CGPointZero;
            view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height-70);
            
            [view.layer renderInContext: UIGraphicsGetCurrentContext()];
            image = UIGraphicsGetImageFromCurrentImageContext();
            
            view.contentOffset = savedContentOffset;
            view.frame = savedFrame;
        }
        UIGraphicsEndImageContext();
        CGImageRef imageRef = image.CGImage;
        CGRect rect =CGRectMake(0,60 ,view.contentSize.width*2, view.contentSize.height*2-208);//这里可以设置想要截图的区域,
        CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
        UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];
        CGImageRelease(imageRefRect);
        return sendImage;
    }

  • 相关阅读:
    查询反模式
    查询反模式
    查询反模式
    查询反模式
    linux vi(vim)常用命令汇总(转)
    面试笔试题之二叉树经典25题
    查找至少一个重复元素
    海盗分金问题
    Output of C++ Program | Set 18
    Output of C++ Program | Set 17
  • 原文地址:https://www.cnblogs.com/shiguangji728/p/4987735.html
Copyright © 2011-2022 走看看