2012-01-30 208 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作爲一種創建屏幕內容視頻的方式。