2011-05-23 71 views
1

如何在Android中查找任何圖像的分辨率。 請建議,謝謝。如何在Android/Java中獲取圖像的解析度?

+1

你的意思是分辨率(每英寸像素)或尺寸(寬度和高度)? – Guffa 2011-05-23 15:16:51

+0

嗨Guffa,是的,它是關於「每英寸像素」。 – CoDe 2011-05-24 07:50:48

回答

3

你可以使用這樣的事情,如果你的形象在你的RES /繪製

Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back); 
bmp.getWidth(), bmp.getHeight(); 
0

我想你可以使用methodes:

myImageBitmap.getWidth(); 
myImageBitmap.getHeight(); 
2

你一定要學會如何短語的問題!既然你沒有提供任何信息,我只能猜測你在做什麼。也許你可以試試這個...

ImageView iv = new ImageView(this); 
iv.getDrawable().getIntrinsicWidth(); 
iv.getDrawable().getIntrinsicHeight(); 
6

高效的方式來獲得圖像的大小存儲在磁盤(例如,獲取用戶選擇的上傳圖片文件的大小)是使用BitmapFactory.Options並將inJustDecodeBounds設置爲true。通過這樣做,您將獲得圖像文件的大小(寬度和高度),而不會將整個圖像加載到內存中。這將有助於在上傳前檢查圖像的分辨率。

String pickedImagePath = "path/of/the/selected/file"; 
BitmapFactory.Options bitMapOption=new BitmapFactory.Options(); 
bitMapOption.inJustDecodeBounds=true; 
BitmapFactory.decodeFile(pickedImagePath, bitMapOption); 
int imageWidth=bitMapOption.outWidth;    
int imageHeight=bitMapOption.outHeight; 
2

我覺得你正在尋找這...

bitmap=MediaStore.Images.Media.getBitmap(getContentResolver(), filePath); 

int imageWidth=bitmap.getWidth(); 

int imageHeight=bitmap.getHeight(); 

嘗試使用這個,讓我知道