2010-09-09 82 views
1

以下步骤允许我获取保存在TomCat服务器上的图像。但我无法从谷歌的网站访问图片。可能是什么原因 ?从互联网上获取图像

     URL aURL = new URL(url); 
     URLConnection con = aURL.openConnection(); 
     con.connect(); 
     InputStream is = con.getInputStream(); 
     /* Buffered is always good for a performance plus. */ 
     BufferedInputStream bis = new BufferedInputStream(is); 
     /* Decode url-data to a bitmap. */ 
     bm = BitmapFactory.decodeStream(bis); 
     bitmapDrawable = new BitmapDrawable(bm); 

我的URL:http://172.29.26.34:8080/MyService/hb.gif

谷歌图片:

http://www.google.co.in/imgres?imgurl=http://www.androidguys.com/wp-content/uploads/2010/04/android_apps.jpeg&imgrefurl=http://www.androidguys.com/2010/04/25/hardware-standards-android-handset-manufacturers-implement/&usg=__VCGb9CrKDVzOjFJxQ0yFHGewblk=&h=356&w=570&sz=156&hl=en&start=0&sig2=N3UL3C995r94inBx8X822w&zoom=1&tbnid=wISGPUJqRDxB7M:&tbnh=127&tbnw=165&ei=h3-ITKDXMov0vQOsg7GPCQ&prev=/images%3Fq%3Dandroid%2Bimages%26um%3D1%26hl%3Den%26sa%3DN%26biw%3D963%26bih%3D525%26tbs%3Disch:1&um=1&itbs=1&iact=rc&dur=188&oei=h3-ITKDXMov0vQOsg7GPCQ&esq=1&page=1&ndsp=15&ved=1t:429,r:2,s:0&tx=107&ty=75

回答

3

这是因为你粘贴的谷歌链接的链接,在一帧的图像浏览器,而不是图片本身。 (实际上,严格来说,图片不是来自谷歌网站,它只是由谷歌索引和显示)

在右栏有一个链接'查看全尺寸图片'去实际图像。

如果您在网站上使用网络图片,请务必检查许可证是否可以接受或获得许可。

0

设置用户代理

的URLConnection CON = aURL.openConnection(); con.setRequestProperty(“User-Agent”,“”);