• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Image from gallery is coming rotated and not in portrait orientation

Joel George

Lurker
May 30, 2018
5
0
I am selecting an image from my gallery, then converting it to a bitmap and putting it on an ImageView.
But the image is not straight or in portrait orientation, it is coming rotated for some reason.

Here is the code :

------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.user.gallery;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

ImageView imageView;
final int image_request_code = 2222;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView = findViewById(R.id.img_pick);
imageView.setOnClickListener(new View.OnClickListener() {

@override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),image_request_code);

}
});

}

@override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if(requestCode==image_request_code) if (resultCode == RESULT_OK) try {

Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
setContentView(R.layout.editor_layout);
imageView = findViewById(R.id.image_display);
imageView.setImageBitmap(bitmap);

} catch (Exception e) {
System.out.println(e.toString());
}

}

}

------------------------------------------------------------------------------------------------------------------------------------------------

Thanks for the Help.
 
What Android device are you using?

You need to first convert to grayscale and then convert from grayscale to bitmap.
  1. 1Open an image that you want to convert to Bitmap mode. You can open the image in either Edit Full or Edit Quick mode.
  2. 2Choose Image→Mode→Bitmap. ...
  3. 3Click OK. ...
  4. 4Select a resolution. ...
  5. 5Select an option from the Use drop-down menu. ...
  6. 6Click OK.
 
Last edited:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones