您的位置:首页 > 产品设计 > UI/UE

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

2014-04-19 15:13 393 查看
YAScreenShotClass.h

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


YAScreenShotClass.m

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: