2012-01-30 124 views
0

我想以编程方式抓取屏幕截图。所以我写它的代码就像,在iPhone中捕捉屏幕截图?

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; 

这里所有的代码是在UIViewController的自定义UIView。现在,当我在UIView上播放UIImageView png序列动画时,我没有在UIImageView的自定义UIView的子视图中更新更改,为什么?我得到的唯一结果是UIImageView与第一个UIImage。

基本上我需要创建一个我的游戏玩像一个谈话汤姆应用程序的视频。

回答

0

把你的ImageView的截图像这样的东西:

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

使用的NSTimer调用该函数getScreenshot。

希望这可以帮助

0

以下代码用于将图像捕获到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); 

还将图像存储到图库中。

+0

对不起朋友我已经按照这段代码,但它不适合我....它给了我同样的结果。 :(upsate – Tirth 2012-01-30 07:13:53

+0

hello RRB:此代码正在工作到我的应用程序捕捉iPhone的截图 – 2012-01-30 07:16:10

+0

我可以给演示的 – 2012-01-30 07:16:58

0

你应该看看AVFoundation,特别是AVAssetWriter作为一种创建屏幕内容视频的方式。