Wednesday, 15 August 2012

iphone - How to show image in webview? -



iphone - How to show image in webview? -

i trying show image in uiwebview.but don't know why image not shown in uiwebveiw. here code.

-(void)pinterest { uiimage *myimage; myimage=imgview.image; webviewcontroller *webviewcontroller = [[webviewcontroller alloc] initwithnibname:@"webviewcontroller" bundle:nil]; webviewcontroller.mypimage = myimage; [[[[uiapplication sharedapplication] keywindow] rootviewcontroller] presentmodalviewcontroller:webviewcontroller animated:yes]; }

now after passing image webviewcontroller webviewcontroller code is,

- (void)viewdidload { nsdata* info = uiimagejpegrepresentation(mypimage, 1.0f); [base64 initialize]; nsstring *strencoded = [base64 encode:data]; nsmutablestring *htmlstring = [[nsmutablestring alloc] initwithcapacity:1000]; [htmlstring appendformat:@"<html> <body>"]; [htmlstring appendformat:@"<p align=\"center\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/pinext.png\" title=\"pin it\" /></a></p>", buttonurl]; [htmlstring appendformat:@"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%@></img></p>", imageurl]; [htmlstring appendformat:@"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"]; [htmlstring appendformat:@"</body> </html>"]; [mywebview setbackgroundcolor:[uicolor clearcolor]]; nsstring *path = [[nsbundle mainbundle] bundlepath]; nsurl *baseurl = [nsurl fileurlwithpath:path]; [mywebview loadhtmlstring:htmlstring baseurl:baseurl]; [mywebview setopaque:no]; }

when tried code show below result.

any help appriated.thanks

try this...

- (void) imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { [imagepicker dismissmodalviewcontrolleranimated:yes]; image= [info objectforkey:@"uiimagepickercontrolleroriginalimage"]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory,nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; savedimagepath = [[documentsdirectory stringbyappendingpathcomponent:@"savedimage.png"] mutablecopy]; nslog(@"savedimagepath..%@",savedimagepath); // imageview image photographic camera imagedata = uiimagepngrepresentation(image); [imagedata writetofile:savedimagepath atomically:yes]; } - (nsstring*) generatepinteresthtml { nsstring *description = @"post description here"; nsstring *stringurl = [nsstring stringwithformat:@"%@",savedimagepath]; nslog(@"stringurl:%@", stringurl); // nsurl *urltoupload = [[nsurl alloc]initfileurlwithpath:stringurl]; surl = [nsstring stringwithformat:@"%@",urltoupload]; // surl = [nsstring stringwithformat:@"http://4.bp.blogspot.com/-w4otzjlpgwo/t5_pi-kjpui/aaaaaaaaaom/rkm3e0xcbgy/s1600/red_rose_flower3.jpg"]; nslog(@"url:%@", surl); nsstring *protectedurl = (__bridge nsstring *)cfurlcreatestringbyaddingpercentescapes(null,(__bridge cfstringref)surl, null, (cfstringref)@"!'\"();:@&=+$,/?%#[]% ",cfstringconvertnsstringencodingtoencoding(nsutf8stringencoding)); nslog(@"protected url:%@", protectedurl); nsstring *imageurl = [nsstring stringwithformat:@"\"%@\"", surl]; nsstring *buttonurl = [nsstring stringwithformat:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%@&description=%@\"", protectedurl, description]; nsmutablestring *htmlstring = [[nsmutablestring alloc] initwithcapacity:1000]; [htmlstring appendformat:@"<html> <body>"]; [htmlstring appendformat:@"<p align=\"center\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/pinext.png\" title=\"pin it\" /></a></p>", buttonurl]; [htmlstring appendformat:@"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%@></img></p>", imageurl]; [htmlstring appendformat:@"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"]; [htmlstring appendformat:@"</body> </html>"]; homecoming htmlstring; } - (void) posttopinterest { nsstring *htmlstring = [self generatepinteresthtml]; nslog(@"generated html string:%@", htmlstring); webviewpinterest.backgroundcolor = [uicolor clearcolor]; webviewpinterest.opaque = no; if ([webviewpinterest ishidden]) { [webviewpinterest sethidden:no]; } [webviewpinterest loadhtmlstring:htmlstring baseurl:nil]; //[webviewpinterest loadhtmlstring:@"<img src=images.png>" baseurl:nil]; }

and if want upload local image first convert imagepath url , seek write code of converting url set comments , pass url...... hope helpful you......

iphone image uiwebview base64 xcode4.5

No comments:

Post a Comment