开发者

Fetching an image from internet

开发者 https://www.devze.com 2023-01-15 04:19 出处:网络
The following steps allow me to fetch an image kept on my TomCat server. but i am unable to access an image from google\'s web site . What could be the reason ?

The following steps allow me to fetch an image kept on my TomCat server. but i am unable to access an image from google's web site . What could be the reason ?

                        URL aURL = new URL(url);
        URLConnection con = aURL.openConnection();
        con.con开发者_C百科nect();
        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);

My URL :http://172.29.26.34:8080/MyService/hb.gif

Google image :

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


It is because the google link you pasted is the link for an image viewer in a frame, not for the picture itself. (And actually, strictly speaking the image is not from google website, it was just indexed and displayed by google)

In the right column there is a link 'view full size picture' to go to the real image.

If you use pictures from the web on your website, be sure to check the license if it is acceptable to do so or seek permission.


Set User-Agent

URLConnection con = aURL.openConnection(); con.setRequestProperty("User-Agent","");

0

精彩评论

暂无评论...
验证码 换一张
取 消