मेरे पास एक UIView है जहां मैं अंदर कुछ सामान खींच रहा था - ड्राव:। अब मुझे इस ग्राफिक्स संदर्भ या UIView के बिटमैप से CGImageRef की आवश्यकता है। क्या इसे पाने का कोई आसान तरीका है?UIView की सामग्री से CGImageRef कैसे प्राप्त करें?
8
A
उत्तर
12
इस तरह
(स्मृति से टाइप किया, तो यह 100% सही नहीं हो सकता है):
// Get a UIImage from the view's contents
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, view.contentScaleFactor);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Convert UIImage to CGImage
CGImageRef cgImage = image.CGImage;
1
भी सुनिश्चित करें कि आप अपने कोड
को
#import <QuartzCore/QuartzCore.h>
जोड़ें: पी एलओएल वास्तव में? हा –