繁体   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