Hi,
is there any Possibility to create a image out of a UIView?
Thanks, Andreas
Hi,
is there any Possibility to create a image out of a UIView?
Thanks, Andreas
#import "QuartzCore/QuartzCore.h"
after you added the framework to your project. Then do:
UIGraphicsBeginImageContext(yourView.frame.size);
[[yourView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// The result is *screenshot
if you have a hierarchy of sub UIViews you should use Apple's approach:
http://developer.apple.com/iphone/library/qa/qa2010/qa1703.html
Ich habe den Ansatz genutzt und noch weiter verbessert. Leider brachte er mir nur ein gespiegeltes Bild.
Hier nun die vollständige Variante:
- (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;
}