我工作的ImageView中,我想設置的圖像轉換成的ImageView但圖像(字節數組)設置圖像直接從Web服務器來..這個概念是:直接從Web服務器來的ImageView
1)我向Web服務器發送各種參數,並且作爲回報,Web服務器向我發送一個特定ID的圖像(只是一個圖像,而不是URL)
2)現在我想直接將Image ImageView而不保存到SD卡中,以便每當用戶想要查看任何其他ID相關的圖像時,圖像應該直接來自服務器,並且我們不會將其保存在我們的末端。
[Editted]從服務器
取值並返回它在字節[]
static BufferedReader in=null;
byte[] result_image;
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(uri1);
if(list!=null)
{
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list);
httpPost.setEntity(formEntity);
}
//URI uri=httpPost.getURI();
HttpResponse httpResponse = httpClient.execute(httpPost);
in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
// String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line +" "); //sb.append(line +NL);
}
in.close();
result_image = String.valueOf(sb).getBytes();
}
catch(UnsupportedEncodingException e)
{
String err = (e.getMessage()==null)?"Cant connect to server":e.getMessage();
Log.e("Network Error:",err);
}
catch (MalformedURLException e) {
String err = (e.getMessage()==null)?"Malformed Exception":e.getMessage();
Log.e("Malformed Exception:",err);
}
catch(Exception ex)
{
// Log.i("Exception,ex", ex.getMessage());
String err = (ex.getMessage()==null)?"NetworkConnectionException":ex.getMessage();
Log.e("NetworkConnectionException:",err);
}
finally {
if (in != null) {
try {
in.close();
} catch (Exception ex) {
String err = (ex.getMessage()==null)?"Excepion":ex.getMessage();
Log.e("Exception:",err);
}
}
這裏result_image是一個字節[]和使用該字節[]正在對其進行解碼並在位圖shwing它..請幫助... 任何幫助,這是非常感謝.. 謝謝..
Web服務器發送給我一張圖片?在哪種格式?是base64字符串,字節數組還是文件? – user370305 2012-04-17 06:23:42
它是一個字節數組 – Kanika 2012-04-17 06:24:57