我试图在缩放后将方形位图设置为线性布局的背景图像。我的位图的大小约为500 * 500,在缩放之后我将作为我的屏幕尺寸为1080 * 1920的背景图像。我可以看到图像被拉伸了。 我怎么能避免这个
这是我的代码
Bitmap alteredBitmap = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();
paint.setFilterBitmap(true);
Matrix matrix = new Matrix();
matrix.setScale(1.5f, 1.5f,original.getWidth()/2,original.getHeight()/2);
canvas.drawBitmap(original, matrix, paint);
Drawable d = new BitmapDrawable(context.getResources(), alteredBitmap);
LinearLayout mRootLayout = (LinearLayout)findViewById(R.id.main);
mRootLayout.setBackground(d);
和布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="false" >