如何從網站中提取圖像並在網格或列表視圖中顯示?從網站提取圖像
Q
從網站提取圖像
0
A
回答
2
Bitmap bmImg;
void downloadfile(String fileurl,ImageView img)
{
URL myfileurl =null;
try
{
myfileurl= new URL(fileurl);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
try
{
HttpURLConnection conn= (HttpURLConnection)myfileurl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
int[] bitmapData =new int[length];
byte[] bitmapData2 =new byte[length];
InputStream is = conn.getInputStream();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize =
bmImg = BitmapFactory.decodeStream(is,null,options);
img.setImageBitmap(bmImg);
//dialog.dismiss();
}
catch(IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
// Toast.makeText(PhotoRating.this, "Connection Problem. Try Again.", Toast.LENGTH_SHORT).show();
}
}
試試這個
0
這url解釋了有關使用異步任務,並在列表視圖中顯示被下載的圖像從遠程服務器下載圖像。
0
下面的代碼可以幫助你獲取圖像。如果你傳遞圖像的網址。
public Drawable loadImageFromWebOperations(String url)
{
try
{
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGetRequest = new HttpGet(url);
HttpResponse response = client.execute(httpGetRequest);
InputStream is = response.getEntity().getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
該代碼將返回您可以在ImageView的
imageView.setImageDrawable(d);
顯示您可以將一個ImageView的添加到列表中的每一行,並設置可繪製的可繪製。
0
如果你想分析整個網站,我更喜歡使用Jerico HTML Parser,它可以在Android上正常工作(試過),然後你可以搜索<img>
元素來獲取圖像的URL。
相關問題
- 1. 從網站獲取圖像
- 2. 如何從簡單的html-dom網站提取圖像?
- 3. 使用jQuery和/或AJAX從網站中提取當前圖像?
- 4. 如何從網站(iOS)提取圖像和標題
- 5. 從網站中提取html
- 6. 從網站提取信息
- 7. 從網站提取價值
- 8. 從網站抓圖像
- 9. 從網站中提取網址?
- 10. 網站圖像
- 11. 從抓取的網站(ARC文件)中提取圖形
- 12. 從RichTextBox中提取圖像
- 13. 從圖像中提取x%
- 14. 從圖像中提取
- 15. 從asp.net提取pdf圖像
- 16. 從網站提取特定行
- 17. 提取從網站使用VBA
- 18. 使用iMacros從網站提取數據
- 19. 從外部網站提取信息
- 20. 從網站提取數據表
- 21. 從網站中提取HTML部分?
- 22. 從網站使用rvest提取表格
- 23. 從網站中提取鏈接
- 24. 從網站提取域和路徑
- 25. 使用python從網站提取數據
- 26. 從Google Play網站提取數據
- 27. Android - 如何從FTP網站提取HTML
- 28. 從網站提取元數據
- 29. 從Google App Engine網站提取數據
- 30. 從URL中提取網站名