2010-08-16 16 views

Odpowiedz

46

#import "QuartzCore/QuartzCore.h" po dodaniu ram do projektu. Następnie wykonaj:

UIGraphicsBeginImageContext(yourView.frame.size); 
[[yourView layer] renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

// The result is *screenshot 
+0

Dzięki! To, czego szukałem. (Tęskniłeś za ";") –

+0

Dzięki, zaktualizowałem swój kod :)! – elslooo

2

Użyłem odpowiedzi, aby ją jeszcze bardziej ulepszyć. Niestety, oryginalny kod wygenerował tylko odbicie lustrzane.

Więc oto kod roboczych:

- (UIImage *) imageFromView:(UIView *)view { 

    UIGraphicsBeginImageContext(view.frame.size); 
    CGContextRef currentContext = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(currentContext, 0, view.size.height); 
    // passing negative values to flip the image 
    CGContextScaleCTM(currentContext, 1.0, -1.0); 
    [[appDelegate.scatterPlotView layer] renderInContext:currentContext]; 
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return screenshot; 
}