我目前有一个视图,我想将其转换为UIImage。我想这样做是因为UIImage类更适合我需要做的事情。您如何捕获UIView的内容并将内容复制到UIImage中?
谢谢,
-David
我目前有一个视图,我想将其转换为UIImage。我想这样做是因为UIImage类更适合我需要做的事情。您如何捕获UIView的内容并将内容复制到UIImage中?
谢谢,
-David
像这样:
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
#import <QuartzCore/CALayer.h>
这里,试试这个
CGImageRef screen = UIGetScreenImage();
UIImage *screenImage = [UIImage imageWithCGImage:screen];
- (UIImage*) capture {
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.opaque, 0.0);
。 - Reed