android中从URL加载图像时出现问题

android中从URL加载图像时出现问题,android,download,bitmap,Android,Download,Bitmap,我正在用android制作一个应用程序,从URL加载图标大小的图像 我尝试过使用以下代码下载图像 从给定url下载了一个标记为default.png的图像,但没有下载另一个标记为v_1234.jpg的图像。我不知道是什么问题。它只是为jpg图像返回null 我不确定.jpg格式是否有问题,因为我的代码没有下载jpg格式的图像,或者是由于标签中的下划线(u)导致无法下载的标签名称问题 请帮助你在这个领域很专业的朋友 代码: URL url = new URL(detail.voucher_imag

我正在用android制作一个应用程序,从URL加载图标大小的图像

我尝试过使用以下代码下载图像

从给定url下载了一个标记为default.png的图像,但没有下载另一个标记为v_1234.jpg的图像。我不知道是什么问题。它只是为jpg图像返回null

我不确定.jpg格式是否有问题,因为我的代码没有下载jpg格式的图像,或者是由于标签中的下划线(u)导致无法下载的标签名称问题

请帮助你在这个领域很专业的朋友

代码:

URL url = new URL(detail.voucher_image.toString());
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.getImageBitmap(bmp);
非常感谢。

试试这段代码

URLConnection conn = url.openConnection();
conn.setDoOutput(true);
InputStream reader;
reader=conn.getInputStream();
System.out.println("Compressed2!!!"+conn.getContentLength());
                int available = reader.available();

                int i=0;
                int count=0;
                int cc=0;

                while(reader.read()!=-1){
                    cc++;
                }
                System.out.println("available"+cc);
                data2 = new byte[cc];
                while ((i = reader.read(data2, count, data2.length-count)) != -1) {
                    count +=i;
                   cc++;
                }


                System.out.println("Compressed3!!!");
               // reader.read(data2,0,cc);
                System.out.println("Compressed!!!");
               // printBytes(data1,data2,"after");

                System.out.println("length b4!!!"+data2);


                System.out.println("data::"+new String(data2));
                System.out.println("The length is "+data2.length);
                bmp2=BitmapFactory.decodeByteArray(data2, 0, data2.length);
                if(bmp2==null)
                    System.out.println("The bitmap value is null");
                iv.setImageBitmap(bmp2);undefined

使用以下代码从url获取位图

public Bitmap imageConvert(String url){
URL aURL = null;
Bitmap bm = null;
try {
final String imageUrl =imgstr.replaceAll(" ","%20");
Log.e("Image Url",imageUrl);
aURL = new URL(imageUrl);
URLConnection conn = aURL.openConnection();
InputStream is = conn.getInputStream(); 
BufferedInputStream bis = new BufferedInputStream(is); 
bm = BitmapFactory.decodeStream(new PatchInputStream(is)); 
is.close(); 
} 
catch (Exception e) {
Log.e("ProPic Exception",e.getMessage());
}
return bm;
}

有时我会遇到类似的问题,有时我得到位图,有时为空,所以我将图像存储为一个文件,下载一个文件,然后创建它的位图