开发者

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

开发者 https://www.devze.com 2023-01-31 03:01 出处:网络
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?

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.


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


If you need a programming way to achieve this you could use:

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


Try pressing the home and close/power button at the same time.

0

精彩评论

暂无评论...
验证码 换一张
取 消