【问题标题】:How to rotate screenshot image with Phonegap Android Screenshot PlugIn如何使用 Phonegap Android Screenshot PlugIn 旋转截图图像
【发布时间】:2012-11-28 14:00:06
【问题描述】:

我正在使用 Phonegap 2.20 Android Screenshot 插件,它工作正常。现在我想保存旋转 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):无法回写 - 未全部读取

所以我想我需要等到文件完成写入?是否有任何监听器或回调或 s.l.t.?

【问题讨论】:

标签: java android cordova plugins exif


【解决方案1】:

那么您将遇到的第一个问题是 ExifInterface 只能读取 jpg 数据而不能读取 png 数据。其次,您可以在 exif 标头中设置方向参数,但这实际上不会旋转图像。它仅向显示图像的程序提供有关如何正确显示图像的提示。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2010-09-26
  • 1970-01-01
  • 1970-01-01
  • 2013-10-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 2021-01-03
相关资源
最近更新 更多