嘿有一些奇怪的顯示出來,當我將位圖轉換從SD卡的可繪製至於調整:Android的 - 位圖轉換從SD卡
String sdDir = Environment.getExternalStorageDirectory().getPath();
String filename = "test.png"; //420px X 420px
Drawable tmpDraw;
Bitmap tmpBit = BitmapFactory.decodeFile(sdDir+filename);
Log.e("BAH","Bitmap height:"+tmpBit.getHeight()); //420
tmpDraw = (Drawable) new BitmapDrawable(getResources(),tmpBit);
int height = tmpDraw.getMinimumHeight();
Log.e("BAH","Drawable height:"+height); //420
我假設我需要一個參照點從縮放?如果從SDCard讀取一個文件,它被歸類爲MDPI,這就是它被重新調整的原因?我目前正在使用Nexus 7來測試哪種TVDPI。我希望縮放發生,就好像位圖是在HDPI中一樣。
任何建議將不勝感激!
想我已經破解了:
String sdDir = Environment.getExternalStorageDirectory().getPath();
String filename = "test.png"; //420px X 420px
Drawable tmpDraw;
BitmapFactory.Options options = new BitmapFactory.Options();
DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
options.inDensity = 240; //Being DPI for HDPI
options.inTargetDensity=metrics.densityDpi; //Being current DPI
//inDensity/inTargetDensity are a ratio
Bitmap tmpBit = BitmapFactory.decodeFile(sdDir+filename,options);
Log.e("BAH","Bitmap height:"+tmpBit.getHeight()); //373 Correct for TVDPI
tmpDraw = (Drawable) new BitmapDrawable(getResources(),tmpBit);
int height = tmpDraw.getMinimumHeight();
Log.e("BAH","Drawable height:"+height); //373 Correct for TVDPI
這是做一個可以接受的方式?
你想要什麼?你想防止縮放,並有高度420而不是315? –
我希望縮放發生,就好像SD卡上的位圖是在HDPI中一樣。在位圖或可繪製級別。 – delaji