我有这个代码来加载图像。服务器是安全的。我得到了回应:200,这意味着好的。然后也将加载正确的 url。问题是当我运行我的应用程序时,图像不会被加载。
try {
Bitmap bitmap=null;
URL imageUrl = new URL(url);
String userPass = username+":"+password;
String encode = Base64.encodeToString(userPass.getBytes(), Base64.DEFAULT);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setRequestProperty("Authorization", "Basic " + encode);
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.setInstanceFollowRedirects(true);
int res = conn.getResponseCode();
System.out.println("Response: " + res);
System.out.println("Image Loader URL: " + url);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
} catch (Throwable ex){
ex.printStackTrace();
if(ex instanceof OutOfMemoryError)
memoryCache.clear();
return null;
}
private Bitmap decodeFile(File f){
try {
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=360;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
Log.d("IMAGE SIZE? ", +width_tmp+ " x " + height_tmp);
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
/// . . . . . and so on...\
在我的 logcat..one 中,它应该 SKImageDecoder::Factory 返回 null
但是后来,也许我做了什么……这就是我在 logcat 中看到的……
04-17 16:18:57.936: D/libEGL(5216): loaded /system/lib/egl/libGLES_android.so
04-17 16:18:57.940: D/libEGL(5216): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
04-17 16:18:57.952: D/libEGL(5216): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
04-17 16:18:57.955: D/libEGL(5216): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
04-17 16:18:58.087: D/OpenGLRenderer(5216): Enabling debug mode 0
我猜我的图像在我登录后被解码IMAGE SIZE?
:然后它记录了我要加载的图像的正确图像大小。
是 ImageLoader 还是渲染部分的问题?
请有任何见解。谢谢。