Java 位图工厂提供空位图
我不明白为什么方法返回null而不是位图。我想做的是读取位图的尺寸,并创建一个更小的新尺寸。我试着跟着这个 请帮忙Java 位图工厂提供空位图,java,android,bitmap,inputstream,Java,Android,Bitmap,Inputstream,我不明白为什么方法返回null而不是位图。我想做的是读取位图的尺寸,并创建一个更小的新尺寸。我试着跟着这个 请帮忙 private Bitmap LoadImageFromWebOperations(String url) { URL myFileUrl =null; try { myFileUrl= new URL(url); } catch (MalformedURLExce
private Bitmap LoadImageFromWebOperations(String url)
{
URL myFileUrl =null;
try {
myFileUrl= new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
/*InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
bitmap = ((BitmapDrawable)d).getBitmap().copy(Config.ARGB_8888, true);*/
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is,null,o);
int IMAGE_MAX_SIZE=960;
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
}
o.inJustDecodeBounds = false;
is.close();
HttpURLConnection conn2= (HttpURLConnection)myFileUrl.openConnection();
conn2.setDoInput(true);
conn2.connect();
InputStream is2 = conn2.getInputStream();
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inMutable=true;
o2.inSampleSize = scale;
o2.inPreferredConfig=Config.ARGB_8888;
o2.inTempStorage = new byte[32*1024];
o2.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeStream(is2, null,o2);
Log.d("nothing>>>>>>>>>>", String.valueOf(o2.outHeight));
// bitmap=bitmap1.copy(Bitmap.Config.ARGB_8888, true);
//bitmap1.recycle();
return bitmap;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}``
您正在将
inJustDecodeBounds
设置为true,如果您将此字段设置为true
则解码器将始终返回null
,如果您将此字段设置为true,则解码器将始终返回null
,如果您选择接受答案,这样其他人就可以轻松找到类似问题的解决方案。@youssoua如果你接受答案,这样其他人就可以轻松找到类似问题的解决方案,那就好了。