Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 位图工厂提供空位图_Java_Android_Bitmap_Inputstream - Fatal编程技术网

Java 位图工厂提供空位图

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

我不明白为什么方法返回null而不是位图。我想做的是读取位图的尺寸,并创建一个更小的新尺寸。我试着跟着这个

请帮忙

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如果你接受答案,这样其他人就可以轻松找到类似问题的解决方案,那就好了。