ios - Capture UIImage from UIView not working -
im trying capture uiimage
uiview
using imagecontext
func captureimage() -> uiimage { uigraphicsbeginimagecontextwithoptions(self.bounds.size, true, 0.0) self.drawviewhierarchyinrect(self.bounds, afterscreenupdates: false) let img = uigraphicsgetimagefromcurrentimagecontext() uigraphicsendimagecontext() return img }
i have tried using renderincontext()
i have in extension
of uiview
i use image mapboxview
subclass uiview
if let viewimage = self.mapview?.resizablesnapshotviewfromrect(frame, afterscreenupdates: false, withcapinsets: uiedgeinsetszero) { let img = viewimage.captureimage() self.view.addsubview(uiimageview(image: img)) }
the img getting returned captureimage()
function black...
viewimage
has right contents when add view instead, there wrong capture method.
resizablesnapshotviewfromrect
return uiview object, don't add object view hierarchy, , don't display view. in case self.drawviewhierarchyinrect
draw nothing.
why don't capture uiimage directly mapview?
if let img = self.mapview?.captureimage() { self.view.addsubview(uiimageview(image: img)) }
Comments
Post a Comment