簡體   English   中英

在不使用Android中的Java堆的情況下在社交應用程序中加載大量位圖?

[英]Loading lots of bitmaps in an social app without using java heap in android?

基本上,我正在制作可滾動的圖像供稿。 它確實有效,但是當我進行內存分析時,我認為我的用戶無法加載很多圖像而不會崩潰。我還為Instagram的應用程序進行了內存分析,發現它們雖然加載了很多圖像,但是它們的堆大小仍然保持不變不管我的屏幕上有多少張圖像都保持不變。可能有3種可能性

1)要么他們正在使用本機內存進行圖像渲染,但我曾嘗試實現該功能,但如果不使用堆就無法渲染圖像(如果您能在這一方面幫助我,那真的很酷)

2)他們使用的inSampleSize大於4,但這實際上不是可能的,因為圖像清晰且中等質量

3)我聞到了本機的openGL接口,是嗎?

我錯過了什么! 請幫忙 !! 我正在使用“ ImageView”加載位圖


即使在內存分析“ Vine應用程序”中,我也發現其Java堆也保持不變,而我的Java堆卻隨着所加載位圖的數量而增加

我現在正在使用此庫https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations

@Override
protected String doInBackground(String[] Params) {


    ParseFile fileObject = (ParseFile)photoObject.get("image");
    try {
        dataMain =  fileObject.getData() ;

        if(dataMain!= null) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            options.inSampleSize = 1;
            options.inSampleSize = calculateInSampleSize(options, context.getResources().getDisplayMetrics().widthPixels,
                    context.getResources().getDisplayMetrics().widthPixels );

            options.inJustDecodeBounds = false;

            options.inPurgeable = true;

            bitmapHolder = new JniBitmapHolder(BitmapFactory.decodeByteArray(dataMain, 0, dataMain.length, options));

            bitmapHolder.scaleBitmap(widthPixels ,widthPixels* bitmapHolder.getBitmap().getHeight() / bitmapHolder.getBitmap().getWidth(), JniBitmapHolder.ScaleMethod.NearestNeighbour);

            //bmp = null ;

        }

    } catch (ParseException e) {
        e.printStackTrace();
    }


    }
        return "done";


}



    @Override
    protected void onPostExecute(String bitmap) {


            ImageView imageView = imageViewReference.get();

            if(imageView!= null && bitmapHolder.getBitmap() != null) {
                imageView.setImageBitmap(bitmapHolder.getBitmapAndFree());

                bitmapHolder = null;


            }

      }

使用Facebook Fresco 它使用ashmem存儲圖像。

您也可以嘗試重用位圖。 閱讀官方文檔以獲取有關有效位圖加載的更多信息。

還可以考慮使用Glide或Picasso庫,而不是手動加載圖像。

我只是想得太深,發現回收者的觀點就完成了工作

暫無
暫無

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

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