0

如何使用 Android-Universal-Image-Loader 共享图像我有一个通过 imageloader 加载的图像视图,但为图像加载器提供了一个 URL,我认为图像加载器已经完成将图像从 URL 写入磁盘然后显示它

如何在不将其重新写入磁盘的情况下共享它?

item_zoom_image_view 是 ImageView selectedItemImage 是一个具有包含 URL ( http://... .)的属性的类

这是我的图像加载器配置:

public void initImageLoader(Context context) {
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheOnDisc().imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .defaultDisplayImageOptions(options)
            .memoryCache(new WeakMemoryCache())
            .denyCacheImageMultipleSizesInMemory()
            .tasksProcessingOrder(QueueProcessingType.LIFO).build();

    imgLoader = ImageLoader.getInstance();
    imgLoader.init(config);
}

这是我显示图像的方式

ImageLoader imgLoader = AppData.imgLoader;
if (!selectedItemImage.getImageURL().trim().equals("")) {
    imgLoader.displayImage(selectedItemImage.getImageURL(), item_zoom_image_view, new ImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            Progress.ShowProgressDialog(true);
            currentImageURI = "";
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
            Progress.HideProgressDialog();;
            currentImageURI = "";
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            Progress.HideProgressDialog();;
            currentImageURI = imageUri;
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
            item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
            Progress.HideProgressDialog();;
            currentImageURI = "";
        }
    });
}
else
{
    item_zoom_image_view.setImageResource(R.drawable.ic_artificial_flowers);
    Progress.HideProgressDialog();;
    currentImageURI = "";
}

这是我分享图像的方式:

void ShareImg() {
    try {
        Uri bmpUri = Uri.parse(currentImageURI);
        if (bmpUri != null) {
            // Construct a ShareIntent with link to image
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            shareIntent.setType("image/*");
            // Launch sharing dialog for image
            startActivity(Intent.createChooser(shareIntent, "Share Image"));
        } else {
            // ...sharing failed, handle error
        }
    } catch (Exception e) {

    }
}

问题是我在显示图像时使用的 URI (currentImageURI) 不正确或者我不知道但它显示的是黑色图像

4

1 回答 1

0

您需要将位图保存在存储中以共享它。您无法共享从 url 下载的图像加载器的缓存图像

 @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap 
     loadedImage) {
        Progress.HideProgressDialog();;
        currentImageURI = imageUri;
              loadedImage
//save it in storage then share
    }
于 2017-04-12T13:06:07.913 回答