简体   繁体   中英

iPhone: can i save the screen or take screen shot to practicular area of view

On my screen there is an image and I have to save this image by taking a screenshot. Is there any other way of saving a particular area of the image only?

If there is a method, please guide me with a simple example.

如果您需要一种编程方式来实现此目的,则可以使用:

[[NSImage alloc] initWithData:[view dataWithPDFInsideRect:[view bounds]]];

The following code will allow you to grab just a section of the screen, you could adapt for full screen

    CGRect screenRect = CGRectMake(0, 0, 200, 200);
UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextFillRect(ctx, screenRect);

[self.view.layer renderInContext:ctx];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    //if you want to save this image to the photo album uncomment the next line
//UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
UIGraphicsEndImageContext();

If you simply want to get a screenshot though just press the home and top button together which will put a screenshot in the photo album each time you do it

尝试同时按下主页和关闭/电源按钮。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM