简体   繁体   中英

How to rotate screenshot image with Phonegap Android Screenshot PlugIn

I am using the Phonegap 2.20 Android Screenshot plugin and it works fine. Now I want to save the image rotated by 270° - but I am new to Java/Android and need some help:

I tried to rewrite the EXIF data as follows

...

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);

but it allways throws the error

E/JHEAD(26853): Can't write back - didn't read all

So I think I need to wait until the file is finished writing? Is there any listener or callback or slt?

Well the first problem you will run into is that the ExifInterface can only read jpg data and not png. Second you can set the orientation parameter in the exif header but that doesn't actually rotate the image. It only gives a hint to programs that display images on how to display them properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM