1

我有一个 480 x 800 的位图,用于我正在创建的动态壁纸。当我在模拟器上测试时,位图宽度和高度可以很好地缩放,但是当我在三星 S3 上测试时,位图宽度可以很好地缩放,但高度太短,底部显示黑色矩形。我应该使用标准位图大小还是我的代码有问题?:

    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);
4

1 回答 1

1

我想你想要Math.max()而不是Math.min()

于 2013-02-19T01:17:54.757 回答