2

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,233
  • 2
  • 24
  • 62
  • 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

2 Answers2

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
  • 5,308
  • 6
  • 33
  • 65
0

This isn't a great solution, but it's something ¯\_(ツ)_/¯

filename.contains("screenshot", ignoreCase = true)
Sámal Rasmussen
  • 2,887
  • 35
  • 36