[Code Note] screenshot function, code note screenshot

Source: Internet
Author: User

[Code Note] screenshot function, code note screenshot

Code:

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // initialization interface [self addView];} # pragma-mark-functions // initialization interface-(void) addView {UIImage * image = [self screenshot: UIDeviceOrientationPortrait isOpaque: YES usePresentationLayer: YES]; UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (50,100,200,200)]; imageView. backgroundColor = [UIColor redColor]; imageView. image = image; [self. view addSubview: imageView];} // screenshot function-(UIImage *) screenshot :( UIDeviceOrientation) orientation isOpaque :( BOOL) isOpaque usePresentationLayer :( BOOL) usePresentationLayer {CGSize size; if (orientation = UIDeviceOrientationPortrait | orientation = UIDeviceOrientationPortraitUpsideDown) {size = CGSizeMake (self. view. frame. size. width, self. view. frame. size. height);} else {size = CGSizeMake (self. view. frame. size. height, self. view. frame. size. width);} uigraphicsbeginimagecontextwitexceptions (size, isOpaque, 0.0); if (usePresentationLayer) {[self. view. layer. presentationLayer renderInContext: UIGraphicsGetCurrentContext ()];} else {[self. view. layer renderInContext: UIGraphicsGetCurrentContext ()];} UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); return image ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.