ios - Take Screenshot of UIImageView and UILabel then Share it -


i think i'm near solving problem. i've uitableview prototype cell looks this: cell
gray-scale background image see coming server , text overlay text uilabel on , change on every image in server. it's two layers i'm trying send. third red button button of share , select share image in email function called:

-(uiimage *)makeimageofcell:(nsuinteger)sender {     homecell *cellobj;     cellobj.tag = sender;     uigraphicsbeginimagecontext(cellobj.homeimg.frame.size );     [cellobj.homeimg.layer renderincontext:uigraphicsgetcurrentcontext()];     [cellobj.overlaytext.layer renderincontext:uigraphicsgetcurrentcontext()];     uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     return viewimage; } 

in -(void)sharebuttonclicked:(uibutton*)sender i've written code of sharing. in function want send image. here i'm doing:

uiimage *imagetoshare = [self makeimageofcell:sender.tag]; calling makeimageofcell function , assigning it's value uiimage. i'm writing share url.

nsstring *imagetoshare = [nsstring stringwithformat:@"hey! check out image %@",imagetoshare]; 


but i'm getting image is: (null). idea how can achieved?

please following code screen shot of uiwindow replace custom view or cell.

- (uiimage*)takescreenshot {     // key-window references     uiwindow *keywindow = [[uiapplication sharedapplication] keywindow];      // manipulate boundries of key-window     cgrect rect = [keywindow bounds];      // create context using size     uigraphicsbeginimagecontextwithoptions(rect.size,yes,0.0f);      // context reference     cgcontextref context = uigraphicsgetcurrentcontext();      // render in context     [keywindow.layer renderincontext:context];      // rendered image     uiimage *capturedscreen = uigraphicsgetimagefromcurrentimagecontext();      // complete context     uigraphicsendimagecontext();      // return image     return takescreenshot; } 

edited

     - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {          uibutton *btnshareimage = (uibutton*)[cell1 viewwithtag:ktagabsentbutton];          [btnshareimage addtarget:self action:@selector(shareimageaction:) forcontrolevents:uicontroleventtouchupinside];          [btnshareimage settitle:[nsstring stringwithformat:@"%li %li",(long)indexpath.section,(long)indexpath.row] forstate:uicontrolstatedisabled];          return cell;      }     -(void)shareimageaction:(uibutton*)sender{         nsstring *str=[sender titleforstate:uicontrolstatedisabled];         nsarray *ar=[str componentsseparatedbystring:@" "];         nsindexpath *indexpath=[nsindexpath indexpathforrow:[[ar objectatindex:1] intvalue] insection:[[ar objectatindex:0] intvalue]];          homecell *cellobj = (homecell*) [yourtableview cellforrowatindexpath:indexpath];         uiimage *imagetoshare = [self makeimageofcell:cellobj];      }     -(uiimage *)makeimageofcell:(homecell*)cellobj     {         uigraphicsbeginimagecontext(cellobj.homeimg.frame.size );         [cellobj.homeimg.layer renderincontext:uigraphicsgetcurrentcontext()];         [cellobj.overlaytext.layer renderincontext:uigraphicsgetcurrentcontext()];         uiimage *viewimage = uigraphicsgetimagefromcurrentimagecontext();         uigraphicsendimagecontext();         return viewimage;     } 

may you.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -