I currently have a view and I would like to change it into a UIImage. I would like to do this because the UIImage class is much better for what I need to do. How would you capture the contents of a UIView and copy the contents into a UIImage?
Thanks,
-David
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
UIImage *img = [UIImage imageNamed:@"anyImageName"];
Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.
An object that manages image data in your app.
Like this:
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
You will need to include the CoreGraphics framework, and import the CALayer.h:
#import <QuartzCore/CALayer.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With