ios - Rendering the layer of a UIWebView that contains an SVG file -


i attempting use method i've constructed save layer of uiwebview image. working svg have loaded uiview not getting rendered in image, background of uiwebview.

+ (bool)imagefromsvginwebview:(uiview *)theview usepng:(bool)usepng; {       uigraphicsbeginimagecontext(theview.frame.size);     [theview.layer renderincontext:uigraphicsgetcurrentcontext()];     uiimage *layerimage = uigraphicsgetimagefromcurrentimagecontext();     uigraphicsendimagecontext();     nsdata *layerimgdata = nil;     nsstring *pathcomponent = nil;     if (usepng) {         layerimgdata = uiimagepngrepresentation(layerimage);         pathcomponent = @"png";     }else {         layerimgdata = uiimagejpegrepresentation(layerimage,1.0f);         pathcomponent = @"jpg";     }     nsstring *appfile = [[ccfilemanagement conversionsdirectory] stringbyappendingpathcomponent:string(@"img.%@",pathcomponent)];     nserror *error = nil;     bool returnbool = [layerimgdata writetofile:appfile options:nsdatawritingatomic error:&error];     if(error != nil)         ilogplus(@"%@",error);     return returnbool; } 

in summary, i've loaded svg uiwebview, saved uiwebview image, opened image , image not have svg in it. have done other views successfully, different svg or uiwebview.

update: if add delay make app wait few seconds execute image saving code works. putting code in webviewdidfinishload not work. webviewdidfinishload doesn't count svgs.

i have found if add .1 second delay work

- (void)webviewdidfinishload:(uiwebview *)webview; {     [self performselector:@selector(postloadactions:) withobject:webview afterdelay:0.1f]; }   - (void)postloadactions:(uiwebview *)webview; {     if (![ccconversion imagefromsvginwebview:webview usepng:yes]) {         ilogplus(@"didn't work");     }     nsarray *array = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:[ccfilemanagement conversionsdirectory] error:null];     ilogplus(@"%@",array);     //[webview removefromsuperview];     [webview release];      uiimageview *imageview = [[uiimageview alloc] initwithimage:[uiimage imagewithcontentsoffile:[[ccfilemanagement conversionsdirectory] stringbyappendingpathcomponent:@"img.png"]]];     imageview.frame = cgrectmake(90, 90, imageview.frame.size.width, imageview.frame.size.height);     imageview.backgroundcolor = [uicolor clearcolor];     [self.view performselector:@selector(addsubview:) withobject:imageview afterdelay:2.0f];     [imageview release]; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -