show a image on the webview

Discussion in 'Mac Programming' started by xiaohuli170, Jan 21, 2009.

  1. macrumors newbie

    Joined:
    Jan 13, 2009
    #1
    I want to shoew a local image on the webview,how to do ,thanks!
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Jan 13, 2009
    #3
    Thanks , I got the answer :
    NSURL *imageURL = [NSURL fileURLWithPath:localImagePath];
    NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
    [[webView mainFrame] loadRequest:request];
     
  4. thread starter macrumors newbie

    Joined:
    Jan 13, 2009
    #4
    Now I want to show few local image of a dic to a webview , How to do ?
     
  5. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #5
    Ah yea I forgot the easiest answer :)

    Can you clarify your second question?
     
  6. thread starter macrumors newbie

    Joined:
    Jan 13, 2009
    #6
    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?
     

Share This Page