如何提高facebook壁画的速度ImageRequest缓存图像位图加载?

时间:2016-12-07 04:01:02

标签: android android-bitmap fresco

我试图在按钮点击事件后从片段中获取壁画缓存图像,以便在whatsapp中共享图像位图!不幸的是,它很慢,点击分享按钮2,3次代码工作!我正在寻找更好的解决方案!!

 ImageRequest imageRequest = ImageRequestBuilder
                            .newBuilderWithSource(Uri.parse("http://example.com/test,jpg"))// disck cached 
                            .setRequestPriority(com.facebook.imagepipeline.common.Priority.HIGH)
                            .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
                            .build();

                    //  .setRequestPriority(Priority.HIGH)

                    DataSource<CloseableReference<CloseableImage>> dataSource =
                            imagePipeline.fetchDecodedImage(imageRequest, this);

                    try {
                        dataSource.subscribe(new BaseBitmapDataSubscriber() {
                            @Override
                            public void onNewResultImpl(@Nullable Bitmap bitmap) {
                                if (bitmap == null) {
                                    Log.d(TAG, "Bitmap data source returned success, but bitmap null.");
                                    return;
                                }

                                sharewithwhatsappBitmap(bitmap);
                                // The bitmap provided to this method is only guaranteed to be around
                                // for the lifespan of this method. The image pipeline frees the
                                // bitmap's memory after this method has completed.
                                //
                                // This is fine when passing the bitmap to a system process as
                                // Android automatically creates a copy.
                                //
                                // If you need to keep the bitmap around, look into using a
                                // BaseDataSubscriber instead of a BaseBitmapDataSubscriber.
                            }

                            @Override
                            public void onFailureImpl(DataSource dataSource) {
                                // No cleanup required here
                                Log.d(TAG, "Bitmap data source onFailureImpl");
                            }
                        }, CallerThreadExecutor.getInstance());
                    } finally {
                        if (dataSource != null) {
                            dataSource.close();
                        }
                    }

我在recyclerview中使用DraweeController,DraweeController更加优化我猜!但不要如何用它来获取一个带位图的图像!!

 public void sharewithwhatsappBitmap(Bitmap bitmap) {
                String path = MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(),
                        bitmap, "Image Description", null);
                Uri bmpUri = Uri.parse(path);
                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                //shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
                shareIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=garbagebin.com.garbagebin");


                shareIntent.setType("image/*");

                //startActivity(Intent.createChooser(shareIntent, "Share Image"));

                shareIntent.setPackage("com.whatsapp");

                        try {
                            startActivity(shareIntent);
                        } catch (android.content.ActivityNotFoundException ex) {

                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));

                        }

            }

第一次调用位图时记录:

 v/unknown:AbstractDraweeController: controller 2a7f5b0e null -> 15: initialize
  V/unknown:AbstractDraweeController: controller 2a7f5b0e 15: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@20cc392f

0 个答案:

没有答案