ios - Draw UIImage on a custom color canvas -


i want draw image example on black canvas, the result white, here code

-(uiimage*) renderimage {     uigraphicsbeginimagecontext(cgsizemake(300, 300));     [[uicolor blackcolor] setfill];     uiimage*resultimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return resultimage; } 

for future draw image inside canvas, right want black filled canvas. why code not working

you need using cgcontextsetfillcolorwithcolor() fill current context color. try sample code, give color , size , return uiimage meeting criteria.

- (uiimage *)renderimagewithcolor:(uicolor *)color insize:(cgsize)size {     cgrect rect = cgrectmake(0.0f, 0.0f, size.width, size.height);     uigraphicsbeginimagecontext(rect.size);     cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsetfillcolorwithcolor(context, [color cgcolor]);     cgcontextfillrect(context, rect);      uiimage *image = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();      return image; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -