简体   繁体   English

捕获iPhone中的屏幕截图?

[英]Capturing screenshot in iphone?

I want to take screenshot programatically. 我想以编程方式拍摄屏幕截图。 So that i write code for it like, 这样我就为它编写代码,

CGContextRef context = [self createBitmapContextOfSize:self.frame.size];

//not sure why this is necessary...image renders upside-down and mirrored
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, self.frame.size.height);
CGContextConcatCTM(context, flipVertical);

[self.layer renderInContext:context];

CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage* background = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);


self.currentScreen = background;

Here all code is in custom UIView of UIViewController. 这里所有代码都在UIViewController的自定义UIView中。 Now when i play UIImageView png sequence animation on UIView, then i didn't get updated changes in UIImageView which is subview of custom UIView, why? 现在,当我在UIView上播放UIImageView png序列动画时,然后在自定义UIView的子视图UIImageView中没有得到更新的更改,为什么? I got only result is UIImageView with first UIImage. 我得到的唯一结果是带有第一个UIImage的UIImageView。

Basically i need to create an video of my game play like talking tom application. 基本上,我需要创建我的游戏视频,例如tom tom application。

Following code is use for the capture the image into the iPhone for that following code to be use. 以下代码用于将图像捕获到iPhone中,以便使用该以下代码。

 CGRect rect = CGRectMake(0.0, 0.0,self.view.frame.size.width,self.view.frame.size.height-44);
    NSValue *rectObj = [NSValue valueWithCGRect:rect];

    CGRect rectRestored = [rectObj CGRectValue];

    UIGraphicsBeginImageContext(CGSizeMake(rectRestored.size.width, rectRestored.size.height-44));
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Also store the image into the gallery. 还将图像存储到图库中。

您可能应该看看AVFoundation,尤其是AVAssetWriter ,它是一种创建屏幕内容视频的方法。

Take the screenshot of your ImageView with something like this: 像这样获取ImageView的屏幕截图:

[[[yourImageView layer] presentationLayer] renderInContext:context];

Use NSTimer for calling that getScreenshot function. 使用NSTimer调用该getScreenshot函数。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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