IOS screenshots-normal screenshots

Source: Internet
Author: User
========================================================== =============================== Original blog, reprinted please declare the source of Electronic coffee (original id blue rock) ========================================================== ================================

Share a piece of screen code, which can be a common button, image, and so on.

It is complicated to capture the image of the camera, because the camera is rendered to the view through OpenGL and cannot be captured through the following code.

It's like when we remotely log on to another Windows computer, we can see the desktop of the other party, but we cannot see the video of the other party.

For how to intercept OpenGL view, I will record it in another blog:

IOS screen --- OpenGL screenshot

I have tested it in my project and can use

// Normal screen capture

First introduce the header:

#include <QuartzCore/QuartzCore.h>

/**@view  the view you want to take screen shot*/-(UIImage*)getNormalImage:(UIView*)view{    UIGraphicsBeginImageContext(CGSizeMake(320,480));    CGContextRef context = UIGraphicsGetCurrentContext();    [view.layer renderInContext:context];    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return image;}

// Store uiiamge in the album

//store the image to the iphone photo albumUIImage *image =nil;// init your imageUIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

// Store the uiimage to a local disk, including the PNG and JPEG formats

//store the image to the app Document-(void)saveToDisk:(UIImage*) image{        NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];    // If you go to the folder below, you will find those picturesNSLog(@"%@",docDir);    NSLog(@"saving png");NSString *pngFilePath = [NSString stringWithFormat:@"%@/test%f.png",docDir,[NSDate timeIntervalSinceReferenceDate]];NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];[data1 writeToFile:pngFilePath atomically:YES];    NSLog(@"saving jpeg");NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test%f.jpeg",docDir,[NSDate timeIntervalSinceReferenceDate]];NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality[data2 writeToFile:jpegFilePath atomically:YES];    NSLog(@"saving image done");}

Ref:

Download an image and save it as PNG or JPEG in iPhone SDK export objectgraph blog

IPhone-why do I get 'no-renderincontext: Method Found 'Warning? -Stack Overflow

IPhone-programmatically take a screenshot combining OpenGL and uikit elements-Stack Overflow

IPhone-saving OpenGL ES content to the photo album | b-101

OpenGL ES-why is glreadpixels () Failing in this code in IOS 6.0? -Stack Overflow

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.