问题
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:
- 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.
- 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:
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.
来源:https://stackoverflow.com/questions/51617172/how-to-make-android-screenshots-saved-as-jpg