从网址获取时,图片会被压缩

时间:2022-09-11 21:23:40

I have the URL of an image and I am fetching the image using Bitmap.

我有一个图像的URL,我使用Bitmap获取图像。

Now my problem is when I am fetching the image will get compressed automatically.

现在我的问题是当我提取图像时会自动压缩。

I want the original image from the URL with the use of Bitmap.

我希望使用Bitmap从URL中获取原始图像。

My current code :

我目前的代码:

InputStream input = new java.net.URL(
                                items.getString(IMAGE1)).openStream();
bitmap = BitmapFactory.decodeStream(input, null,
                                options);
image1.setImageBitmap(bitmap);

How can I get the image without compressing it?

如何在不压缩图像的情况下获取图像?

1 个解决方案

#1


The Universal Image Loader may be your solution, as stated in the comments.

如评论中所述,Universal Image Loader可能是您的解决方案。

Excerpt from the Github page:

摘自Github页面:

  • Many customization options for every display image call (stub images, caching switch, decoding options, Bitmap processing and displaying, etc.)
  • 每个显示图像调用的许多自定义选项(存根图像,缓存切换,解码选项,位图处理和显示等)

  • Image caching in memory and/or on disk (device's file system or SD card)
  • 内存和/或磁盘上的图像缓存(设备的文件系统或SD卡)

  • Listening loading process (including downloading progress)
  • 听力加载过程(包括下载进度)

// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});

or

/ Load image, decode it to Bitmap and return Bitmap synchronously
Bitmap bmp = imageLoader.loadImageSync(imageUri);

#1


The Universal Image Loader may be your solution, as stated in the comments.

如评论中所述,Universal Image Loader可能是您的解决方案。

Excerpt from the Github page:

摘自Github页面:

  • Many customization options for every display image call (stub images, caching switch, decoding options, Bitmap processing and displaying, etc.)
  • 每个显示图像调用的许多自定义选项(存根图像,缓存切换,解码选项,位图处理和显示等)

  • Image caching in memory and/or on disk (device's file system or SD card)
  • 内存和/或磁盘上的图像缓存(设备的文件系统或SD卡)

  • Listening loading process (including downloading progress)
  • 听力加载过程(包括下载进度)

// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});

or

/ Load image, decode it to Bitmap and return Bitmap synchronously
Bitmap bmp = imageLoader.loadImageSync(imageUri);