Last active
December 14, 2015 21:28
-
-
Save monjer/5151183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Screenshot.h | |
| // | |
| // Created by manjun.han on 13-3-13. | |
| // Copyright (c) 2013年 com.hmj. All rights reserved. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface UIView (Screenshot) | |
| - (UIImage*)screenshot ; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Screenshot.m | |
| // | |
| // Created by manjun.han on 13-3-13. | |
| // Copyright (c) 2013年 com.hmj. All rights reserved. | |
| // | |
| #import "UIView+Screenshot.h" | |
| #import <QuartzCore/QuartzCore.h> | |
| @implementation UIView (Screenshot) | |
| - (UIImage*)screenshot | |
| { | |
| // 如果bitmap是彻底不透明的,设置opaque = YES,来优化bitmap的存储。貌似生成的bitmap会忽略alpha通道值 | |
| UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0); | |
| CGContextRef ctx = UIGraphicsGetCurrentContext() ; | |
| [self.layer renderInContext:ctx]; | |
| UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); | |
| return image; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment