0

I am using ExifInterface to save information for image description. But because screenshots are save .png and ExifInterface doesn't work on .png, I cannot save image description for screenshots.

I have two options:

  1. Every time I need to save EXIF image description, I need to first convert the screenshots to .jpg format, and then edit its EXIF data.
  2. Or I can just set the phone to save all screenshots as .jpg files. So whenever I save a screenshot (by pressing the volume down key+power button), the screenshot is saved right there and then as .jpg. No hassle trying to convert it later.
joe doe
  • 117
  • 9

1 Answers1

1

You can take advantage of a View's drawing cache.

myView.setDrawingCacheEnabled(true);
Bitmap b = view.getDrawingCache();
b.compress(CompressFormat.JPEG, 95, new FileOutputStream("/some/location/image.jpg"))

Where view is your View. The 95 is the quality of the JPG compression. And the file output stream is just that.

petey
  • 16,914
  • 6
  • 65
  • 97
olajide
  • 972
  • 1
  • 13
  • 26
  • This works only if I am taking screenshots of my app. What about when I need to take a screenshot of an app that I have no control over? – joe doe Aug 01 '18 at 17:18
  • You are building screen grabber app. Use broadcast service to capture such event and return it as an intent to your app – olajide Aug 01 '18 at 17:45
  • https://play.google.com/store/apps/details?id=com.jaredco.screengrabber8&hl=en_US I saw this app that captures screenshot using a transparent button you can drag around. Can I configure physical buttons to capture screenshots? – most venerable sir Aug 01 '18 at 18:43
  • The transparent button is a widget. You can create a widget and let `BroadcastService` handle event that your app requires. – olajide Aug 01 '18 at 18:56
  • Could you find any tutorial on make a complete screen grabber app? Most tutorials are about taking screenshot of one's own app. Thank you for the help thus far. – joe doe Aug 02 '18 at 13:04
  • That is another question, and not for comment box. You can simply ask new question again. Mind you, according to your question, my provided answer is the correct one. You can simply mark it as answer to help others looking for similar solutions. – olajide Aug 02 '18 at 22:56