【问题标题】:how to fetch images from url on webView in ios如何从ios中webView上的url获取图像
【发布时间】:2013-09-18 02:08:16
【问题描述】:

http://www.imageurlhost.com/viewer.php?is_random=1&file=9psik7w1j5rkef8kek5.jpg

图像代码 - 1wba395mv72m3of2ikz.jpg

我用过这个。

NSURL *imageURL = [NSURL URLWithString:@"http://www.imageurlhost.com/viewer.php?file=1wba395mv72m3of2ikz.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];

UIImageView *imgview1 =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150,150 )];

imgview1.image= image;

[scrlview addSubview:imgview1];

【问题讨论】:

  • 那么您将需要解析从该 URL 返回的 HTML 并查找图像。然后,当您拥有图像 URL 时,从中加载 UIImage
  • @rckoenes: url 返回图片或其他?
  • @preetam 如果您从帖子中打开其中一个 URL,您会看到它加载了一个网页。
  • @rckoenes: 是的...我以为是图片网址...
  • 如果您按照 rckoenes 的建议以编程方式执行此操作,则必须解析 HTML。否则,如果您只是在图片 URL 之后,我想这就是 imageurlhost.com/download.php?file=1wba395mv72m3of2ikz.jpg(来自网页上的“下载”按钮)。

标签: ios image url webview fetch


【解决方案1】:

你可以像这样在图像视图中设置图像

[imageView setImageWithURL:[NSURL URLWithString:@"your url string"] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];

placeholder.png 是在接收到来自 url 的图像时替换的任何临时图像

【讨论】:

    【解决方案2】:

    Rahul paliwal ...您的 url 是 html 页面..如果您想在 imageview 中加载图像,请使用正确的 url... 如果你想在 imagview 中加载图像...比如 这……

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多