ImageButton自动旋转选定的图像

时间:2018-09-27 21:59:03

标签: android android-studio android-view android-imagebutton

我不想以任何方式更改从图库中选择的图像。我只希望所选的图像按原样显示在ImageButton视图中。因为,如果在从手机存储中选择图像后旋转图像,则图像将以相同状态上载到数据库,并且也将以相同(旋转)状态获取。有些图像会旋转,而另一些则不会。因此,我无法编写通用代码来使所选图像的旋转无效。

activity_post.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="15dp"
    tools:context=".PostActivity">

    <ImageButton
        android:id="@+id/post_image_button"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

PostActivity.java 中与ImageButton相关的部分

public class PostActivity extends AppCompatActivity {

    private ImageButton selectCardImage;

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_post);    

        selectCardImage = findViewById(R.id.post_image_button);    
        selectCardImage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                OpenGallery();
            }
        });

    private void OpenGallery() {

        Intent galleryIntent = new Intent();
        galleryIntent.setType("image/*");
        galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(galleryIntent, 1);
    }
}

0 个答案:

没有答案