0

I am uploading an image from my gallery and setting it as a bitmap. In my scenario, whenever I upload a screenshot from gallery,

The bitmap looks clean and fit

But, when I upload a picture which was taken from back/front camera, the bitmap is rotated 90 degrees.

How do I detect if an gallery image was taken by camera or screenshot?

grantespo
  • 2,001
  • 2
  • 22
  • 56
  • 1
    Images from the camera are .jpg. Screenshots are .png. – greenapps Mar 07 '17 at 20:49
  • I don't believe the correct solution to your problem is to check if it was taken by a screenshot or a camera. This is a well known bug in Android: http://stackoverflow.com/questions/8865183/android-rotates-pictures-by-90-degrees-taken-by-camera – Waclock Mar 07 '17 at 21:47

1 Answers1

2

Check if the dimensions of the image fits with the dimensions of the screen. Considering bitmap is the image you want to check:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
if(bitmap.getWidth() == size.x && bitmap.getHeight() == size.y){
    // Then is a screenshot
}else{
    // Then is not a screenshot
}
Damia Fuentes
  • 4,940
  • 3
  • 28
  • 59