How to make Android screenshots saved as .jpg?

2019-09-20 22:20发布

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.

1条回答
贼婆χ
2楼-- · 2019-09-20 23:05

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.

查看更多
登录 后发表回答