ExifInterface oldExif = new ExifInterface(oldImagePath); String exifOrientation = oldExif.getAttribute(ExifInterface.TAG_ORIENTATION); if (exifOrientation != null) { ExifInterface newExif = new ExifInterface(imagePath); newExif.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation); newExif.saveAttributes(); }
value = originalExif.getAttribute(attribute); if (!TextUtils.isEmpty(value)) { newExif.setAttribute(attribute, value); newExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(width)); newExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(height)); newExif.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
value = originalExif.getAttribute(attribute); if (!TextUtils.isEmpty(value)) { newExif.setAttribute(attribute, value); newExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(width)); newExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(height)); newExif.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + getPhotoOrientation(configurationProvider.getSensorPosition())); exif.saveAttributes();
/** * Store the exif attributes in the passed image file using the TAGS stored in the passed bundle * * @param filepath * @param bundle * @return true if success */ public static boolean saveAttributes( final String filepath, Bundle bundle ) { ExifInterface exif; try { exif = new ExifInterface( filepath ); } catch ( IOException e ) { e.printStackTrace(); return false; } for ( String tag : EXIF_TAGS ) { if ( bundle.containsKey( tag ) ) { exif.setAttribute( tag, bundle.getString( tag ) ); } } try { exif.saveAttributes(); } catch ( IOException e ) { e.printStackTrace(); return false; } return true; }
public static boolean copyExifRotation(File sourceFile, File destFile) { if (sourceFile == null || destFile == null) return false; try { ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath()); ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath()); exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION)); exifDest.saveAttributes(); return true; } catch (IOException e) { Log.e("Error copying Exif data", e); return false; } }
value = sourceExif.getAttribute(tag); if (!TextUtils.isEmpty(value)) { saveExif.setAttribute(tag, value); saveExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(outputWidth)); saveExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(outputHeight)); saveExif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_UNDEFINED));
String mString = "Your message here"; ExifInterface exif = new ExifInterface(path_of_your_jpeg_file); exif.setAttribute("UserComment", mString); exif.saveAttributes();
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitudeStr); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, lat>0?"N":"S"); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitudeStr); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, lon>0?"E":"W");
public void loc2Exif(String flNm, Location loc) { try { ExifInterface ef = new ExifInterface(flNm); ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE, dec2DMS(loc.getLatitude())); ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,dec2DMS(loc.getLongitude())); if (loc.getLatitude() > 0) ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N"); else ef.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S"); if (loc.getLongitude()>0) ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E"); else ef.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W"); ef.saveAttributes(); } catch (IOException e) {} } //----------------------------------------------------------------------------------- String dec2DMS(double coord) { coord = coord > 0 ? coord : -coord; // -105.9876543 -> 105.9876543 String sOut = Integer.toString((int)coord) + "/1,"; // 105/1, coord = (coord % 1) * 60; // .987654321 * 60 = 59.259258 sOut = sOut + Integer.toString((int)coord) + "/1,"; // 105/1,59/1, coord = (coord % 1) * 60000; // .259258 * 60000 = 15555 sOut = sOut + Integer.toString((int)coord) + "/1000"; // 105/1,59/1,15555/1000 return sOut; }
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + getPhotoOrientation(cameraConfigProvider.getSensorPosition())); exif.saveAttributes();
newExif.setAttribute(attributes[i], value);
ExifInterface exif = new ExifInterface(filePath.getAbsolutePath()); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPS.latitudeRef(latitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude)); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPS.longitudeRef(longitude)); exif.saveAttributes();
int degrees = 90; ExifInterface exif = new ExifInterface(path); exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(degrees)); exif.saveAttributes();
ExifInterface exif = new ExifInterface(pictureFile.toString()); exif.setAttribute(ExifInterface.TAG_ORIENTATION, "3"); exif.saveAttributes();
ExifInterface exifForNewImage = new ExifInterface(newFile.getAbsolutePath()); //Pass the origImageOrientation value that you get from the original image exifForNewImage.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation); //Then save the Exif attributes exifForNewImage.saveAttributes();
String filePath = Enviroment.getExternalStorageDirectory() + "/MyApp/photo.png"; OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filePath))); photo.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); ExifInterface exif = new ExifInterface(filePath); // call this next setAttributes a few times to write all the GPS data to it. exif.setAttribute(... ); // don't forget to save exif.saveAttributes();
ExifInterface exif = new ExifInterface(filename); int old_orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); int new_orientation = ...; // implement your business logic here exif.setAttribute(TAG_ORIENTATION, new_orientation); exif.saveAttributes();
public static boolean copyExifRotation(File sourceFile, File destFile) { if (sourceFile == null || destFile == null) return false; try { ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath()); ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath()); exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION)); exifDest.saveAttributes(); return true; } catch (IOException e) { return false; } }
public static boolean copyExifRotation(File sourceFile, File destFile) { if (sourceFile == null || destFile == null) return false; try { ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath()); ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath()); exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION)); exifDest.saveAttributes(); return true; } catch (IOException e) { return false; } }