首页 > 其他 > 详细

截图UIView的某个CGRect,返回图片

时间:2014-04-19 19:34:05      阅读:519      评论:0      收藏:0      [点我收藏+]

YAScreenShotClass.h

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
@interface YAScreenShotClass : NSObject
+(UIImage *)screenShotFrom:(UIView *)view frame:(CGRect)frame;
@end

YAScreenShotClass.m

bubuko.com,布布扣
#import "YAScreenShotClass.h"

@implementation YAScreenShotClass
+(UIImage *)screenShotFrom:(UIView *)view frame:(CGRect)frame
{
    if(UIGraphicsBeginImageContextWithOptions != NULL)
    {
        UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0);
    } else {
        UIGraphicsBeginImageContext(frame.size);
    }
    
    //获取图像
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
@end
bubuko.com,布布扣

 

截图UIView的某个CGRect,返回图片,布布扣,bubuko.com

截图UIView的某个CGRect,返回图片

原文:http://www.cnblogs.com/hushuai-ios/p/3675045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!