Java 位图未缩放到高度
我有一个480 x 800位图,我正在为我正在创建的实时壁纸使用。在模拟器上测试时,位图宽度和高度缩放良好,但在三星S3上测试时,位图宽度缩放良好,但高度太短,底部显示黑色矩形。是否有我应该使用的标准位图大小,或者我的代码中是否有错误Java 位图未缩放到高度,java,android,android-canvas,Java,Android,Android Canvas,我有一个480 x 800位图,我正在为我正在创建的实时壁纸使用。在模拟器上测试时,位图宽度和高度缩放良好,但在三星S3上测试时,位图宽度缩放良好,但高度太短,底部显示黑色矩形。是否有我应该使用的标准位图大小,或者我的代码中是否有错误 public void doDraw(Canvas c) { c.drawColor(Color.rgb(0,0,0)); // Clear the background. final int canvasWidth = getScree
public void doDraw(Canvas c) {
c.drawColor(Color.rgb(0,0,0)); // Clear the background.
final int canvasWidth = getScreenWidth();
final int canvasHeight = getScreenHeight();
int imageWidth = mBitmap.getWidth();
int imageHeight = mBitmap.getHeight();
float scaleFactor = Math.min( (float)canvasWidth / imageWidth,
(float)canvasHeight / imageHeight );
Bitmap scaled = Bitmap.createScaledBitmap( mBitmap,
(int)(scaleFactor * imageWidth),
(int)(scaleFactor * imageHeight),
true );
c.drawBitmap(scaled, 0, 0, null);
我想你想要
Math.max()
而不是Math.min()
我想你想要Math.max()
而不是Math.min()