Is there a way to resize a JPEG image file (from filesystem to filesystem) without removing meta data (just like ImageMagicks convert in.jpg -resize 50% out.jpg
)?
The only way I found to resize .jpg files I found is BitmapFactory.decodeStream
and Bitmap.compress
, which looks like a lot of overhead if I manually need to transfer image meta data.
To batch-convert the images you press "Batch" button, add your images, choose "Additional tasks" -> "Compress to size" option, set desired filesize threshold and start the process.
It may be possible to read the metadata with android.media.ExifInterface, compress the image via Bitmap.compress
and then save the metadata back:
String filename = "yourfile.jpg";
// this reads all meta data
ExifInterface exif = new ExifInterface(filename);
// read and compress file
Bitmap bitmap = BitmapFactory.decodeFile(filename);
FileOutputStream fos = new FileOutputStream(filename);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
// write meta data back
exif.saveAttributes();
I didn't test it, but looking at the source code of ExifInterface, it may work. If you don't want to rely on the implementation details, you could of course loop through all attributes and copy them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With