2

基本上我正在制作一个可滚动的图像提要。它有效。但是当内存分析时,我认为我的用户无法加载大量图像而不会崩溃。我也在为 Instagram 的应用程序进行内存分析,发现虽然他们正在加载大量图像,但它们的堆大小仍然存在无论我的屏幕上有多少图像,都保持不变。可能有 3 种可能性

1)要么他们使用本机内存进行图像渲染,但我尝试过实现它,但不使用堆我无法渲染图像(如果你能在这个问题上帮助我,那就太酷了)

2)他们使用大于 4 的 inSampleSize 但这实际上是不可能的,因为图像清晰且质量中等

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;


            }

      }
4

2 回答 2

0

使用 Facebook壁画。它使用 ashmem 来存储图像。

您也可以尝试重用位图。阅读官方文档以获取有关高效位图加载的更多信息。

还可以考虑使用 Glide 或 Picasso 库而不是手动加载图像。

于 2015-12-31T13:52:20.693 回答
0

我只是想多了,原来回收者的观点只是做了这个工作

于 2016-01-08T13:07:22.387 回答