開發一個圖形應用程序,應該對任何屏幕大小的工作需要一些思考 通常我創建高分辨率的圖形,並以適合屏幕的規模。Android的位圖 - 最佳實踐
我見過的建議,以避免使用「實像素」 我試圖與密度和DP的工作,但它似乎更復雜然後用我用 與解決找不到更好的方式來擴展其他我的圖形然後使用該設備屏幕(實像素)
我創造了這個類來擴展我的圖片(基於真實像素) 這解決了我的大部分問題(仍然有一些設備具有不同的縱橫比) ,似乎做工精細。
public class BitmapHelper {
// Scale and keep aspect ratio
static public Bitmap scaleToFitWidth(Bitmap b, int width) {
float factor = width/(float) b.getWidth();
return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), false);
}
// Scale and keep aspect ratio
static public Bitmap scaleToFitHeight(Bitmap b, int height) {
float factor = height/(float) b.getHeight();
return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factor), height, false);
}
// Scale and keep aspect ratio
static public Bitmap scaleToFill(Bitmap b, int width, int height) {
float factorH = height/(float) b.getWidth();
float factorW = width/(float) b.getWidth();
float factorToUse = (factorH > factorW) ? factorW : factorH;
return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorToUse), (int) (b.getHeight() * factorToUse), false);
}
// Scale and dont keep aspect ratio
static public Bitmap strechToFill(Bitmap b, int width, int height) {
float factorH = height/(float) b.getHeight();
float factorW = width/(float) b.getWidth();
return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factorW), (int) (b.getHeight() * factorH), false);
}
}
和我的問題是:
- 爲什麼避免 「實像素」 建議?
- 什麼是縮放位圖到屏幕的最佳實踐(教程 的好文章更然後歡迎)
- 什麼是使用我使用的方法或者我應該知道使用這種方法 時的利弊
感謝您的意見
[編輯] 我忘了提,我通常使用SurfaceView我的應用程序(如果這有什麼區別)
另請參見[this](http ://stackoverflow.com/a/823966/556337)。這將是有益的爲你的智能解碼的ByteArray的問題,以位圖 – teoREtik 2011-12-20 17:50:38