简体   繁体   English

在不使用Android中的Java堆的情况下在社交应用程序中加载大量位图?

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

Basically I am making an image feed which is scrollable. 基本上,我正在制作可滚动的图像供稿。 And it works.But when memory profiling I don't think my users will be able to load lots of images without crashing.I was also doing memory profiling for Instagram's app and found out though they are loading lots of images but their heap size remains constant no matter how many images i have on my screen.There could be 3 possibilities 它确实有效,但是当我进行内存分析时,我认为我的用户无法加载很多图像而不会崩溃。我还为Instagram的应用程序进行了内存分析,发现它们虽然加载了很多图像,但是它们的堆大小仍然保持不变不管我的屏幕上有多少张图像都保持不变。可能有3种可能性

1)either they are using native memory for image rendering ,but I had tried implementing that but I am unable to render images without using the heap (if you can help me on this one it would be really cool ) 1)要么他们正在使用本机内存进行图像渲染,但我曾尝试实现该功能,但如果不使用堆就无法渲染图像(如果您能在这一方面帮助我,那真的很酷)

2)they are using inSampleSize greater than 4 but that is really not possibe since the images are clear and medium quality 2)他们使用的inSampleSize大于4,但这实际上不是可能的,因为图像清晰且中等质量

3)I smell native openGL interface in this , is it ? 3)我闻到了本机的openGL接口,是吗?

Am I missing Out something !! 我错过了什么! please help !! 请帮忙 !! I am using "ImageView" to load bitmaps 我正在使用“ ImageView”加载位图


Even when memory profiling "Vine app" I found their java heap remains constant too whereas my java heap increase with the number of bitmaps loaded 即使在内存分析“ Vine应用程序”中,我也发现其Java堆也保持不变,而我的Java堆却随着所加载位图的数量而增加

I am using this library right now https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations 我现在正在使用此库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;


            }

      }

Use Facebook Fresco . 使用Facebook Fresco It uses ashmem to store images. 它使用ashmem存储图像。

You may also try reusing bitmaps. 您也可以尝试重用位图。 Read official docs to get more about efficient bitmap loading. 阅读官方文档以获取有关有效位图加载的更多信息。

Also consider using Glide or Picasso libraries instead of manual image loading. 还可以考虑使用Glide或Picasso库,而不是手动加载图像。

我只是想得太深,发现回收者的观点就完成了工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM