1
我有一个480 x 800的位图,我用它来创建一个动态壁纸。当我在模拟器上测试时,位图的宽度和高度都很好地缩放,但是当我在Samsung S3上测试时,位图宽度可以很好地缩放,但高度太短,在底部显示黑色矩形。有没有一个标准位图大小,我应该用或者工作时有什么错在我的代码?:位图不能缩放到高度Android
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);
感谢那些工作就像一个魅力! – 2013-02-19 03:00:29