2010-08-16 22 views

cevap

46

#import "QuartzCore/QuartzCore.h" projenize çerçeve ekledikten sonra. Sonra yapın:

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

// The result is *screenshot 
+0

Teşekkür:

Yani burada çalışma kodu! Benim aradığım şey buydu. (Siz bir “;” kaçırdınız) –

+0

Teşekkürler, kodumu güncelledim :)! – elslooo

2

Daha da geliştirmek için cevabı kullandım. Maalesef, orijinal kod sadece yansıtılmış bir görüntü oluşturdu.

- (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; 
}