How to get the height and width of an image when android:minSdkVersion="8" -


normally, can use following code width of image, require api level 16. how height , width of image when android:minsdkversion="8"

cursor cur = mycontext.getcontentresolver().query(                 mediastore.images.media.external_content_uri, null,                 mediastore.images.media._id + "=?", new string[] { id }, ""); string width=cur.getstring(cur.getcolumnindex(mediastore.images.media.height)); 

pass option decode bounds factory:

bitmapfactory.options options = new bitmapfactory.options(); options.injustdecodebounds = true;  //returns null, sizes in options variable bitmapfactory.decodefile("/sdcard/image.png", options); int width = options.outwidth; int height = options.outheight; //if want, mime type decoded (if possible) string type = options.outmimetype; 

or

you can height , width of imageview using getwidth() , getheight() through while not give exact width , height of image, getting image width height first need drawable background convert drawable tobitmapdrawable` image bitmap can width , height here

bitmap b = ((bitmapdrawble)imageview.getbackground()).getbitmap(); int w = b.getwidth(); int h = b.getheight(); 

or way

imageview.setdrawingcacheenabled(true); bitmap b = imageview.getdrawingcache(); int w = b.getwidth(); int h = b.getheight(); 

the above code give current imageview sized bitmap screen shot of device

for imageview size

imageview.getwidth(); imageview.getheight(); 

if have drawable image , want size can way

drawable d = getresources().getdrawable(r.drawable.yourimage); int h = d.getintrinsicheight(); int w = d.getintrinsicwidth(); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -