android - Get width and Height from URI of picture -


i trying widht , height of picture able load canvas on activity. when try print height , width 0. not understand why ?

here code:

    private void openpicture() {         bitmapfactory.options options = new bitmapfactory.options();         options.injustdecodebounds = true;         try {             inputstream stream = context.getcontentresolver().openinputstream(uri);             bitmapfactory.decodestream(stream);             int width = options.outwidth;             int height = options.outheight;             log.d("debug", ""+ width);             loadpicture(width, height);         } catch(ioexception e) {             log.e("fingerpainterview", e.tostring());         }     }      private void loadpicture(int w, int h) {          try {             // attempt load uri provided, scale fit our canvas             inputstream stream = context.getcontentresolver().openinputstream(uri);             bitmap bm = bitmapfactory.decodestream(stream);             bitmap  = bitmap.createscaledbitmap(bm, math.max(w, h), math.max(w, h), false);             stream.close();             bm.recycle();         } catch(ioexception e) {             log.e("fingerpainterview", e.tostring());         }         canvas = new canvas(bitmap);     } 

private void getimagewidthandheight(uri uri){    bitmapfactory.options options = new bitmapfactory.options();    options.injustdecodebounds = true;    bitmapfactory.decodefile(new file(uri.getpath()).getabsolutepath(), options);    int imageheight = options.outheight;    int imagewidth = options.outwidth;  } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -