我正在使用 Phonegap 2.20 Android 屏幕截图插件,它工作正常。现在我想保存旋转 270° 的图像 - 但我是 Java/Android 的新手,需要一些帮助:
我尝试如下重写EXIF数据
...
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
String filename = "Screenshot_" + dateFormat + ".png";
File f = new File(folder, filename); // System.currentTimeMillis()
//FileOutputStream fos = openFileOutput(f.getPath(), Context.MODE_PRIVATE);
FileOutputStream fos = new FileOutputStream(f);
// change image orientation to landscape
ExifInterface exif = new ExifInterface(filename);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "8"); // ExifInterface.ORIENTATION_ROTATE_270
exif.saveAttributes();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
//fos.close();
//Log.w(TAG, "TAG_ORIENTATION: " + exif.getAttribute(ExifInterface.TAG_ORIENTATION));
that.success(new PluginResult(PluginResult.Status.OK), id);
但它总是抛出错误
E/JHEAD(26853): Can't write back - didn't read all
所以我觉得我需要等到文件写完?有没有监听器或者回调或者s.l.t.?
最佳答案
您将遇到的第一个问题是 ExifInterface 只能读取 jpg 数据而不能读取 png 数据。其次,您可以在 exif header 中设置方向参数,但实际上不会旋转图像。它只是提示显示图像的程序如何正确显示它们。
关于java - 如何使用 Phonegap Android 截图插件旋转截图图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13606822/