简体   繁体   English

如何使用Android-Universal-Image-Loader共享图像?

[英]How to share image using Android-Universal-Image-Loader?

How to share an image using Android-Universal-Image-Loader I have an imageview which is loaded through imageloader but providing a URL to the image loader, I think the image loader already done writing the image from URL to disk and then displayed it 如何使用Android-Universal-Image-Loader共享图像我有一个通过imageloader加载的imageview,但提供了图像加载器的URL,我认为图像加载器已经完成了将图像从URL写入磁盘然后显示的操作

how can I share it without re-writing it to disk? 如何共享它而不将其重新写入磁盘?

item_zoom_image_view is ImageView selectedItemImage is a class that has a property that contains the URL ( http://... .) item_zoom_image_view是ImageView selectedItemImage是具有包含URL( http:// ... )的属性的类。

here is my image loader config: 这是我的图像加载器配置:

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);
}

and here is how I display the image 这是我显示图像的方式

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 = "";
}

Here is how I share the image: 这是我分享图片的方式:

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) {

    }
}

the problem is that the URI which I took while displaying the image (currentImageURI) is not correct or i don't know but it shows a black image 问题是我在显示图像时使用的URI(currentImageURI)不正确或我不知道,但显示的是黑色图像

you need to save bitmap in storage to share it. 您需要将位图保存在存储中以进行共享。 you cannot share cache image which image loader download from url 您不能共享从URL下载图像加载器的缓存图像

 @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap 
     loadedImage) {
        Progress.HideProgressDialog();;
        currentImageURI = imageUri;
              loadedImage
//save it in storage then share
    }

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

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