2012-03-27 166 views
1

我使用這段代碼來捕捉我的屏幕。捕捉一些iphone屏幕

 CGImageRef screen = UIGetScreenImage(); 
    UIImage* image = [UIImage imageWithCGImage:screen]; 
    CGImageRelease(screen); 
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

這段代碼佔用了所有的屏幕。 我只需要一些它... CGRect rect = CGRectMake (0,0,100,100);

我可以通過任何參數來得到它嗎?

謝謝!

回答

1

聽起來像你只是想要或需要裁剪你的UIImage。

在此相關的問題檢查出來的代碼,看看它是否可以幫助你:

How to crop the UIImage?

+0

這是不可能得到一定大小的uiimage? – OAZ 2012-03-27 12:55:16

4

,你也可以定義一個新的上下文的矩形大小,你想:

CGRect rect = CGRectMake (0,0,100,100); 
UIGraphicsBeginImageContext(rect); 
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(screenshot, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

Nota:您需要在進口中添加QuartzCore:

#import <QuartzCore/QuartzCore.h> 

,你可以得到主視圖:

UIView *view = [[UIApplication sharedApplication].keyWindow rootViewController].view 
+0

抓住這樣的最高級別的看法是非常有益的,謝謝! – 2014-03-13 18:44:43

1

使用此代碼捕獲屏幕並自動保存到iPhone設備中的圖像庫。

UIGraphicsBeginImageContext(self.view.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);