簡體   English   中英

顯示來自URL的圖像,Android應用程序運行緩慢

[英]Show image from URL, Android-app goes extremly slow

我試圖通過URL在我的應用程序中顯示圖像,但是(僅當)位圖顯示時,應用程序太慢了。 該應用程序運行正常,但是當我加載圖像時,它的運行速度非常慢。 有人可以幫忙嗎?

因此,我有一個名為ImageDownload的類來進行下載,在我的Fragment中,我有:

new ImageDownload((ImageView) login_image, this.getActivity().getApplicationContext(),"login_image")
        .execute(path);

這是我的下載類:

public class ImageDownload extends AsyncTask<String, Void, Bitmap> {
private Context mContext;
private String filename;
ImageView bmImage;

public ImageDownload(ImageView bmImage, Context mContext, String filename) {
    this.bmImage = bmImage;
    this.mContext = mContext;
    this.filename = filename;
}

protected Bitmap doInBackground(String... urls) {
    String urldisplay = urls[0];
    Bitmap mIcon11 = null;
    try {
        InputStream in = new java.net.URL(urldisplay).openStream();

        mIcon11 = BitmapFactory.decodeStream(in,null,null);
        //EDIT:

        in.close();

        // The isuue is not soved yet 

    } catch (Exception e) {

        e.printStackTrace();

    }
    return mIcon11;
}

protected void onPostExecute(Bitmap result) {

    bmImage.setImageBitmap(result);

}

}

然后是ImageBitmap大小和平板電腦RAM大小的問題。 將ImageBitmap加載到RAM上會占用太多RAM。 您可以通過查看日志來檢測到此錯誤,因為系統面臨的頻繁頁面遺漏比頁面擊中要頻繁,因此System.gc()的調用頻率非常高,幾乎像是抖動問題。 我確信系統是如此頻繁地調用.gc() ,並且System.gc()是在GUI線程中調用的,這會干擾UI體驗。

您應該使用Google的Volley庫

使用畢加索 簡單又酷。

我終於找到了答案。 看看這個。 將來可能對您有幫助。 謝謝大家。 這完美地工作:

http://www.technotalkative.com/android-load-images-from-web-and-caching/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM