title: How to get image dimensions from a network url for png image in android
body: <p>I need to grab dimensions of image (preferably without loading) from a network url given from the server. Here is the method I tried to get this. </p>
  
  <pre><code>public void getBitmapDimensions(String uri){
      try {
          URL uri1 = new URL(uri);
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(new File(uri1.toString()).getPath(), options);
          int imageHeight = options.outHeight;
          int imageWidth = options.outWidth;
  
          Log.d("NewDimens1",imageWidth+","+imageHeight+","+options.inSampleSize);
      } catch (MalformedURLException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The string url works perfectly when opened in a browser. But in this case, the imageHeight and imageWidth are always 0. </p>
  
  <p>I have tried using Uri instead of URL as well. Same thing. Does it need to done different when url is network based and not file based?</p>
  
  <p>Also, I am originally loading the image url into view using Glide library. I tried to change </p>
  
  <pre><code>Glide.with(this.getContext().getApplicationContext()).load(url).diskCacheStrategy(DiskCacheStrategy.ALL).into(this);
  </code></pre>
  
  <p>To </p>
  
  <pre><code>Glide.with(this.getContext().getApplicationContext()).load(url).
              diskCacheStrategy(DiskCacheStrategy.ALL).
              into(new SimpleTarget&lt;GlideDrawable&gt;() {
                  @Override
                  public void onResourceReady(GlideDrawable resource, GlideAnimation&lt;? super GlideDrawable&gt; glideAnimation) {
                      Log.wtf("DimensionsAre",resource.getIntrinsicWidth()+","+resource.getIntrinsicHeight());
                  }
              });
  </code></pre>
  
  <p>Now this does give me the image dimensions but it wrecks up my original setup for imageview provided by loading the image using <code>.into(this)</code> context. </p>