繁体   English   中英

从Android中的URL加载图像

[英]Load Image from URL in Android

我正在尝试从以下URL加载图像: https ://fangkarte.de: 8080/ fangfisch/ file/ files/ 592036af55dfffca0155e01fe10002f7

在Chrome / IE中,图像将正确显示。 当我尝试在Android上加载图像时,无法将图像存储为PNG文件。 每次图像将被保存为文本文件,其中包含图像为base64字符串。

我也尝试了以下代码,但codedByte为空:

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

有谁知道如何将URL中的图像显示为位图,或者我更喜欢将图像存储为png?

使用Universal Image Loder从Url上传图像下载Universal Image Loder并添加到您的lib文件夹中,然后

在要加载图像的位置实现以下代码

ImageLoader imageLoader = ImageLoader.getInstance();

imageLoader.init(ImageLoaderConfiguration.createDefault(context));

DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
        .cacheOnDisc(true).resetViewBeforeLoading(true)
        .showImageForEmptyUri(R.drawable.noimage)
        .showImageOnFail(R.drawable.icon3)
        .showImageOnLoading(R.drawable.loading).build();

imageLoader.displayImage(url, imageview, options);

要处理图像,请使用Picasso,Glide,Universal图像加载器,Volley或Fresco

例如,在毕加索中,您将能够加载图像,将其存储在内存缓存中并处理listviews / recyclerviews等中的取消操作...

Picasso.with(context).load(“ https://fangkarte.de:8080/fangfisch/file/files/592036af55dfffca0155e01fe10002f7 ”).placeholder(“ someimagetillyourimagedownloads).into(R.id.yourimageview);

毕加索: https : //github.com/square/picasso

滑行: https : //github.com/bumptech/glide

壁画: https : //github.com/facebook/fresco (我在广泛测试了除凌空以外的所有3个之后使用了它)

UIL: https//github.com/nostra13/Android-Universal-Image-Loader

使用上述所有库都可以完成类似的操作。

我强烈建议不要尝试自行处理图像。 如果您是新手android开发人员,可能会变得一团糟。

您下载的图像很大((860.000字节)),可以从中制作出位图。 因此,BitmapFactory将返回null。

使用前按比例缩小图像。

暂无
暂无

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

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