2

I am having a problem when loading a webview. Header part having two images which are stored locally.

and body content and back ground images are given by client url. 1)Header part should be scrolled. 2)Get the path for local images with out using base url because in baseURL we are giving client url to get the body background images.

 NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

    NSString *absStirng=[[[NSBundle mainBundle] resourceURL] absoluteString];
        printf("\n absStirng=============================== %s",[absStirng UTF8String]);
    NSString* appendString=@"";
    appendString = [appendString stringByAppendingString:@"<body>"];
        appendString =[appendString stringByAppendingString:@"<table background="];
        appendString =[appendString stringByAppendingString:absStirng];
        appendString =[appendString stringByAppendingString:@"myimage.png width='320' height='45' style='background-repeat:no-repeat'>"]; // here unable to get local image with full path as given.
        appendString =[appendString stringByAppendingString:@"<tr>"];
        appendString =[appendString stringByAppendingString:@"<td align='left' width='57' height='31' style='padding: 6px 0 0 0' ><a href='/map/'><img src="];
        appendString =[appendString stringByAppendingString:absStirng];// here unable to get local image with full path as given.v
        appendString =[appendString stringByAppendingString:@"backButton.png></a></td>"];
        appendString =[appendString stringByAppendingString:@"<td align='left' valign='middle' style='padding: 0 0 0 65px; font-family:Helvetica; font-size:21px ; font-weight:bold ; color:#FFF'>Details</td>"];
        appendString =[appendString stringByAppendingString:@"</tr>"];
        appendString =[appendString stringByAppendingString:@"</table>"];
        returnString = [returnString stringByReplacingOccurrencesOfString:@"<body>" withString:appendString];


        [webView loadHTMLString:returnString baseURL:[NSURL URLWithString:@"http://client url given here"]];

What the problem is? how to get the local images path with out reference to baseURL.

Please help me and any one help will be appreciated.

Thank you, Madan Mohan.

Madan Mohan
  • 8,764
  • 17
  • 62
  • 96

2 Answers2

5

You may insert base64 encoded images as

<img src="data:image/png;base64,SJGFSDGBDFSBGSDFGRKYG2Y32YTHWEGIDSF==" alt="" />

To convert image try http://www.abluestar.com/utilities/encode_base64/index.php that will create img tag for you.

Andriy
  • 1,864
  • 1
  • 12
  • 10
  • Now it is retrieving from net, if that server is down for some days. then how can i get image? – Madan Mohan Jan 06 '11 at 11:37
  • @user468443: for first image I am not using image tag. I set the image as table background. then how I can insert image tag there? – Madan Mohan Jan 06 '11 at 12:03
  • With terminal openssl base64 [type input] – Andriy Jan 06 '11 at 12:06
  • Apply CSS style for that table background: url('data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/ //+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC') – Andriy Jan 06 '11 at 12:08
  • @user468443:Thanks for ur suggestion actually as per ur suggestion the image is getting from the net if the server is down for couple of weeks at that time how can we retrieve the image and it will become a big problem. – Monish Kumar Jan 06 '11 at 12:43
  • Per my suggestion you encode images to Base64 string, add them into your generated HTML as in sample from Wiki and internet connection is NOT needed at all to display that images. – Andriy Jan 06 '11 at 13:01
0
  1. You can use full URL for remote images;
  2. You can embed base64-encoded local images into HTML.
Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48