當前位置:首頁 » 安卓系統 » android網路獲取圖片

android網路獲取圖片

發布時間: 2023-03-26 16:17:35

Ⅰ android 網路圖片查看器 無法獲取伺服器上的圖片

你直接在手機的瀏覽器裡面輸入這個地址也可以顯示出這個圖片嗎?
先懷疑一種可能性:你的手機上網方式不和電腦在一個區域網內部,也就是說不能通過192.168.***來訪問你自己伺服器上的圖片,你可以先換一張公共網路圖片的地址來調試。

Ⅱ Android viewpager的高度動態設置為網路獲取到的圖片的高度 怎麼設置試了各種方法都不行

用自定猛陪義的view就可枝攔蠢以,重寫viewPager的onMeasure方法。源代碼衡指已上傳

java" wealth="5" />

Ⅲ android 載入網路圖片錯誤

如果使用固定地址,如每個用戶頭像都是用戶id+什麼什麼的,固定下來,這樣更新有兩種:
1。每次都重新載入。(不符合)。
2。伺服器在返回其它數據的api中返回一個標記。通過標記判斷。
對於2,如果用單獨api去獲取是否更新,有點浪費。選擇你每次都要訪問的api,伺服器那邊在其中加一個關於頭像是否更新的標記。這樣,只需要一次api訪問就能一並解決這個問題。

Ⅳ 如何通過網路獲取圖片和文字信息顯示在android的listview中

通過httpurlconnection或者HTTPclient通過線程訪問網路,並且你這個返回的是JSON數據。通過數據解析,得到封裝成實體類,然後綁定數據在listview上。

Ⅳ Android如何獲取網路圖片

android中獲取網路圖片是一件耗時的操作,如果直接獲取有可能會出現應用程序無響應(ANR:Application Not Responding)對話框的情況。對於這種情況,一般的方法就是耗時操作用線程來實現。下面列三種獲取url圖片的方法:


  1. 直接獲取:(容易:ANR,不建議)

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
mImageView.setImageDrawable(drawable);

2. 後台線程獲取url圖片:

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newThread(newRunnable(){
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
@Override
publicvoidrun(){

//post()特別關鍵,就是到UI主線程去更新圖片
mImageView.post(newRunnable(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
mImageView.setImageDrawable(drawable);
}});
}

}).start();

3.AsyncTask獲取url圖片

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newDownloadImageTask().execute(IMAGE_URL);
<String,Void,Drawable>
{

(String...urls){
returnloadImageFromNetwork(urls[0]);
}
protectedvoidonPostExecute(Drawableresult){
mImageView.setImageDrawable(result);
}
}

Ⅵ android關於網路上獲取圖片後保存在本地的問題

private InputStream ins = null;

....

HttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(server_path_up);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httppost);
HttpEntity entity = response.getEntity();

ins = entity.getContent();

這個ins是一個數據流,然後通過BitmapFactory.decodeStream(ins)就可以得到這個圖片了。得到圖片後保存到sd卡上,也是通過數據流保存,方法雷同。

Ⅶ Android如何從伺服器獲取圖片

  • 直接獲取bitmap對象

  • //傳輸網路圖片

  • publicBitmapgetPic(StringuriPic){

  • URLimageUrl=null;

  • Bitmapbitmap=null;

  • try{

  • imageUrl=newURL(uriPic);

  • }catch(MalformedURLExceptione){

  • e.printStackTrace();

  • }

  • try{

  • HttpURLConnectionconn=(HttpURLConnection)imageUrl

  • .openConnection();

  • conn.connect();

  • InputStreamis=conn.getInputStream();

  • bitmap=BitmapFactory.decodeStream(is);

  • is.close();

  • }catch(IOExceptione){

  • e.printStackTrace();

  • }

  • returnbitmap;

  • }

Ⅷ 如何在Android當中顯示網路圖片

在android當中顯示一張網路圖片的時候,其實是比較麻煩的。首先得把這個網路圖片轉換成java的imputstream流,然後再把這個留轉換成一個bitMap.
bitMap是可以作為參數傳給imageView的。

在下邊的returnBitMap函數是最核心的,也是大家可以重用的,它負責把一個url的網路圖片變成一個本地的BitMap。

packagecom.jinyan.image;

importjava.io.IOException;
importjava.io.InputStream;
importjava.net.HttpURLConnection;
importjava.net.MalformedURLException;
importjava.net.URL;

importandroid.app.Activity;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ImageView;

{
/**.*/

StringimageUrl="http://i.pbase.com/o6/92/229792/1/80199697.uAs58yHk.50pxCross_of_the_Knights_Templar_svg.png";
BitmapbmImg;
ImageViewimView;

Buttonbutton1;

@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView=(ImageView)findViewById(R.id.imview);
imView.setImageBitmap(returnBitMap(imageUrl));


}

publicBitmapreturnBitMap(Stringurl){
URLmyFileUrl=null;
Bitmapbitmap=null;
try{
myFileUrl=newURL(url);
}catch(MalformedURLExceptione){
e.printStackTrace();
}
try{
HttpURLConnectionconn=(HttpURLConnection)myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStreamis=conn.getInputStream();
bitmap=BitmapFactory.decodeStream(is);
is.close();
}catch(IOExceptione){
e.printStackTrace();
}
returnbitmap;
}

}

Ⅸ android bitmap 從網路獲取圖片並處理問題 溢出

在 Java中,JavaVM擁有自動管理內存的功能,Java的GC能夠進行垃圾回收,但是如果ImageView使用過多的Bitmap的話,經常會報OOM(內存溢出)。

造成內存溢出及解決方案:

  1. 使用BitmapFactory.decodeStream替代createBitmap方法

    原因是該方法直讀取圖片位元組,調用JNI>>nativeDecodeAsset()來完成decode,無需再使用java層的createBitmap。

  2. 使用壓縮讀取技術

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

BitmapFactory.decodeFile(imageSdUri, options);

final int height = options.outHeight;

final int width = options.outWidth;

options.inSampleSize = 1;

int w = 320;

int h = 480;

h = w*height/width;//計算出寬高等比率

int a = options.outWidth/ w;

int b = options.outHeight / h;

options.inSampleSize = Math.max(a, b);

options.inJustDecodeBounds = false;

Bitmap bitmap = BitmapFactory.decodeFile(imageSdUri, options);


3.及時釋放Bitamp
Bitmap對象在不使用時,我們應該先調用recycle()釋放內存,然後才它設置為null.雖然recycle()從源碼上看,調用它應該能立即釋放Bitmap的主要內存,但是測試結果顯示它並沒能立即釋放內存。但是我它應該還是能大大的加速Bitmap的主要內存的釋放。

Ⅹ android根據url獲取網路圖片報錯

這個看著是https協議的URL,用普通的http請求就報錯了,我這里只有請求https到流的代碼,給你先看看,把流再轉成文件 就可以了


@SuppressLint("ParserError")
(StringdownUrl,StringpostStr)throwsIOException{
Stringres="";

HttpsURLConnection.setDefaultHostnameVerifier(newNullHostNameVerifier());
SSLContextcontext=null;
try{
context=SSLContext.getInstance("TLS");
}catch(NoSuchAlgorithmExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}

try{
context.init(null,newX509TrustManager[]{newmyX509TrustManager()},newSecureRandom());
}catch(KeyManagementExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());

URLdUrl=newURL(downUrl);
HttpsURLConnectiondConn=(HttpsURLConnection)dUrl.openConnection();

dConn.setDoInput(true);
if(postStr!=""){
dConn.setDoOutput(true);
dConn.setRequestMethod("POST");
}

dConn.connect();

if(postStr!=""){
try{
BufferedWriterout=newBufferedWriter(newOutputStreamWriter(
dConn.getOutputStream()));
out.write(postStr);
out.flush();

}catch(Exceptione){
StringerrMsg=e.getMessage();
if(null!=errMsg){
Toasttoast=Toast.makeText(null,errMsg,Toast.LENGTH_LONG);
toast.show();
}

e.printStackTrace();
}

}


BufferedInputStreamin=newBufferedInputStream(dConn.getInputStream());

returnin;
}


{
@Override
publicbooleanverify(Stringhostname,SSLSessionsession){
//Log.i("RestUtilImpl","Approvingcertificatefor"+hostname);
returntrue;
}
}

{
@Override
publicX509Certificate[]getAcceptedIssuers(){
returnnull;
}

@Override
publicvoidcheckClientTrusted(X509Certificate[]chain,StringauthType)
throwsCertificateException{
//TODOAuto-generatedmethodstub
}

@Override
publicvoidcheckServerTrusted(X509Certificate[]chain,StringauthType)
throwsCertificateException{
//TODOAuto-generatedmethodstub
}
}
熱點內容
linuxshell密碼 發布:2025-05-14 17:21:11 瀏覽:199
安卓手機聽筒在哪裡關閉 發布:2025-05-14 17:16:20 瀏覽:454
我的世界炸毀50萬伺服器 發布:2025-05-14 17:16:07 瀏覽:123
存儲站源 發布:2025-05-14 17:14:20 瀏覽:864
win2008的ftp設置 發布:2025-05-14 17:03:31 瀏覽:663
萊克發的工資卡密碼是多少 發布:2025-05-14 16:57:10 瀏覽:178
方舟怎麼用自己的存檔進入別人的伺服器 發布:2025-05-14 16:46:25 瀏覽:878
微博視頻高清上傳設置 發布:2025-05-14 16:38:41 瀏覽:548
資料庫圖書管理設計 發布:2025-05-14 16:33:52 瀏覽:378
php開發的網頁 發布:2025-05-14 16:22:03 瀏覽:478