PDA

View Full Version : show a image on the webview




xiaohuli170
Jan 21, 2009, 02:08 AM
I want to shoew a local image on the webview,how to do ,thanks!



kainjow
Jan 21, 2009, 11:06 AM
There are two ways. One is to add an NSImageView as a subview, the other is to create a temp HTML page with the <img> element.

xiaohuli170
Jan 21, 2009, 08:29 PM
Thanks , I got the answer :
NSURL *imageURL = [NSURL fileURLWithPath:localImagePath];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
[[webView mainFrame] loadRequest:request];

xiaohuli170
Jan 21, 2009, 09:22 PM
Now I want to show few local image of a dic to a webview , How to do ?

kainjow
Jan 22, 2009, 02:36 PM
Ah yea I forgot the easiest answer :)

Can you clarify your second question?

xiaohuli170
Feb 2, 2009, 01:13 AM
first Thanks a lot.
My second question is that I want to show some images of one directory to the webview, because I can show a image to the webview ,but some images ? How to do ? by the way , I want to click a button and to open the homeDirectory and choose a directory , some images within it will show in the webview, how to do? I found a similar sample, the path is :/developer/examples/webkit/picturebrowser. but it is hard . I want to a simple demo or code ,how to do?