ios - Mask out specific pixels from a UIView based on where subviews are located -
say have main uiview has several subviews of type catview , dogview. want render uiview image, want exclude dogviews, final rendered image has transparent pixels in place of dogview. (note removing dogviews view wouldn't work - need transparent pixels dogviews were). dogviews can rotated don't take rectangular portions of view.
any ideas on how can approach this?
edit: first attempt
- (uiimage *)createcutoutviewfromview:(uiview*)view { uigraphicsbeginimagecontextwithoptions(view.bounds.size, no, 0.0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextmovetopoint(context, 200, 200); cgcontextaddlinetopoint(context, 250, 200); cgcontextaddlinetopoint(context, 250, 250); cgcontextaddlinetopoint(context, 200, 250); cgcontextclosepath(context); cgcontextclip(context); [view.layer renderincontext:context]; uiimage *result = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return result; }
the result can see 50px rectangle clipped. want see except rectangle. advice?
edit: 2nd attempt
- (uiimage *)createcutoutviewfromview:(uiview*)view { uigraphicsbeginimagecontextwithoptions(view.bounds.size, no, 0.0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextclearrect(context, view.bounds); [view.layer renderincontext:context]; uibezierpath* path = [uibezierpath bezierpath]; [path movetopoint:cgpointmake(200, 200)]; [path addlinetopoint:cgpointmake(250, 200)]; [path addlinetopoint:cgpointmake(250, 250)]; [path addlinetopoint:cgpointmake(200, 250)]; [path closepath]; [path fillwithblendmode:kcgblendmodenormal alpha:0.0]; uiimage *result = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return result; }
create bitmapped graphics context , render view context. each dogview, create uibezierpath, , use movetopoint
, addlinetopoint
, , closepath
draw outline dogview be. call fillwithblendmode:alpha:
alpha of 0.0 clear region of drawing.
i use uigraphicsbeginimagecontext
create bitmapped graphics context since needs size, can view's bounds. here's general framework.
uigraphicsbeginimagecontext( view.bounds.size ); cgcontextref context = uigraphicsgetcurrentcontext(); // drawing stuff goes here uiimage *result = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext();
Comments
Post a Comment