我有一個應用程序,您可以在其中拍照,然後將其顯示爲相對佈局的背景。但是不知何故,圖像會以一種奇怪的方式被拉伸,也許被強制爲橫向模式(?)。我不知道如何以正確的方式旋轉它,這是我的代碼,希望有人能幫助。Android位圖拉伸?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main2);
Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES).getAbsolutePath();
String filePath = Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES) + "/picFolder/1.jpg";
File image = new File(filePath);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
Drawable drawable = new BitmapDrawable(bitmap);
RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout);
layout1.setBackgroundDrawable(drawable);
}
我的第一張圖片是原來的一個,第二個是streched,我在我的佈局得到。
如何解決這個問題?我做錯了什麼?提前致謝!