2010-08-15 14 views

risposta

9

ho trovato questo, ma non ho provato io stesso:

http://reusablesnippets.posterous.com/capture-uiview

Qui trova il utilizzato -renderInContext:http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004500-CH1-SW120

modificare

ho trasformato i codici sopra per un categoria su UIView. chiamare in questo modo: [aView saveScreenshotToPhotosAlbum];

#import <QuartzCore/QuartzCore.h> 

- (UIImage*)captureView { 

    CGRect rect = [[UIScreen mainScreen] bounds]; 
    UIGraphicsBeginImageContext(rect.size);  
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [self.layer renderInContext:context]; 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 
} 



- (void)saveScreenshotToPhotosAlbum { 
    UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil); 

} 
+0

Questo funziona per i livelli normali. I livelli OpenGl non verranno visualizzati nello screenshot. Lo screenshot di UIWebview fallirà se l'html avrà -transformare css. – 2mia

Problemi correlati