对于从远程 Web 服务器请求的图像与本地请求的图像相比,Drawable.createFromStream 似乎更慢。这有意义吗?
我有以下代码通过 HTTP 从 Web 服务器获取图像以用于 android 应用程序。
HttpClient httpclient = new DefaultHttpClient();
HttpParams httpparams = httpclient.getParams();
HttpConnectionParams.setConnectionTimeout(httpparams, CONNECT_TIMEOUT_MS);
HttpConnectionParams.setSoTimeout (httpparams, CONNECT_TIMEOUT_MS);
// For test only
long time = System.currentTimeMillis();
HttpResponse response = httpclient.execute(new HttpGet(strUrl));
StatusLine statusLine = response.getStatusLine();
Log.w("getimage", "Time to get image was " + (System.currentTimeMillis() - time) + "ms");
// Check response
if(statusLine.getStatusCode() == HttpStatus.SC_OK)
{
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
Log.w("getimage", "This is how many bytes we skipped: " + inputStream.skip(1000000));
image = Drawable.createFromStream(inputStream, "src name");
}
Log.w("getimage", "Time to return from image call was " + (System.currentTimeMillis()-time) + "ms");
如果我指向我的本地站点(本地网络),第一个计时器日志是 30 毫秒(HTTP 请求),第二个是 66 毫秒(HTTP 请求,加上可绘制对象)。
如果我做同样的事情,但指向我的 Web 服务器,我得到 298 毫秒(预计它会更慢......),但是 HTTP 请求和可绘制对象调用需要 1800 毫秒。
这告诉我 Drawable.createFromStream 方法在远程 Web 服务器上要多花 1.5 秒?
对此有什么想法吗?它是否执行任何 HTTP 调用?文档很少。在本地运行时一切都是肉汁,但在远程运行时变得非常慢......