headkit
headkit

Reputation: 3327

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 s.l.t.?

Upvotes: 1

Views: 831

Answers (1)

Simon MacDonald
Simon MacDonald

Reputation: 23273

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.

Upvotes: 3

Related Questions