我怎样才能从下面网址加载图像。 http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450
How can I load image from below url . http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450
我使用谷歌自定义搜索API从网站 images.google.com 搜索图像。它会返回一个链接标签内容的JSON文件。例如: http://images.google.com/hosted/life/l?imgurl = 46d75bbfa52a8450 。我想加载到我的看法。
I use Google Custom Search API to search image from site images.google.com . It will return a json file with contents of link tag . Example : https://m.xsw88.com/allimgs/daicuo/20230906/3384.png.jpg或.png,我可以下载并显示它。但如果不是这样,我可以得到图像。任何人都可以帮助我。
If URL is endwith file extends ".jpg or .png", i can download and display it . But if not , i can get the image . Anyone can help me .
喜请使用以下code。
Hi Please used below code.
String url = "http://images.google.com/hosted/life/l?imgurl=46d75bbfa52a8450";
InputStream ins = null;
try {
ins = new java.net.URL(url).openStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap b = BitmapFactory.decodeStream(new FlushedInputStream(ins));
imageview.setImageBitmap(b);
static class FlushedInputStream extends FilterInputStream {
public FlushedInputStream(InputStream inputStream) {
super(inputStream);
}
@Override
public long skip(long n) throws IOException {
long totalBytesSkipped = 0L;
while (totalBytesSkipped < n) {
long bytesSkipped = in.skip(n - totalBytesSkipped);
if (bytesSkipped == 0L) {
int b = read();
if (b < 0) {
break; // we reached EOF
} else {
bytesSkipped = 1; // we read one byte
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}