Android Open Source - FxCameraApp Exif Utils From Project Back to project page FxCameraApp .
License The source code is released under:
MIT License
If you think the Android project FxCameraApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.af.experiments.FxCameraApp.Utils;
/ * w w w . j a v a 2 s . c o m * /
import android.location.Location;
import android.media.ExifInterface;
import android.os.Build;
import android.util.Log;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class ExifUtils {
private static final String TAG = "ExifUtils" ;
private static final String DATE_FORMAT = "yyyy:MM:dd" ;
private static final String TIME_FORMAT = "HH:mm:ss" ;
private static final String DATETIME_FORMAT = DATE_FORMAT + " " + TIME_FORMAT;
private ExifUtils() {}
public static int getAngle(final String filename) throws IOException {
final ExifInterface exif = new ExifInterface(filename);
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
case ExifInterface.ORIENTATION_ROTATE_270:
return 270;
case ExifInterface.ORIENTATION_ROTATE_180:
return 180;
case ExifInterface.ORIENTATION_ROTATE_90:
return 90;
case ExifInterface.ORIENTATION_NORMAL:
default :
return 0;
}
}
private static final String TAG_GPS_DATESTAMP = "GPSDateStamp" ;
public static void save(final String filename, final Date datetime, final int orientation, final Boolean flash, final Location location) throws IOException {
final ExifInterface exif = new ExifInterface(filename);
if (datetime != null) {
exif.setAttribute(ExifInterface.TAG_DATETIME, new SimpleDateFormat(DATETIME_FORMAT, Locale.ENGLISH).format(datetime));
}
exif.setAttribute(ExifInterface.TAG_MAKE, Build.MANUFACTURER);
exif.setAttribute(ExifInterface.TAG_MODEL, Build.MODEL);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(orientation));
if (flash != null) {
exif.setAttribute(ExifInterface.TAG_FLASH, String.valueOf(flash.booleanValue() ? 1 : 0));
}
if (location != null) {
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N" );
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, formatExifGpsDMS(location.getLatitude()));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E" );
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, formatExifGpsDMS(location.getLongitude()));
exif.setAttribute(TAG_GPS_DATESTAMP, new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH).format(datetime));
}
exif.saveAttributes();
}
private static String formatExifGpsDMS(final double d) {
final double degrees = Math.floor(d);
final double minutes = Math.floor((d - degrees) * 60D);
final double seconds = (d - degrees - minutes / 60D) * 3600D * 1000D;
final String _degrees = String.valueOf((int ) degrees);
final String _minutes = String.valueOf((int ) minutes);
final String _seconds = String.valueOf((int ) seconds);
return new StringBuilder()
.append(_degrees).append("/1," )
.append(_minutes).append("/1," )
.append(_seconds.substring(0, Math.min(_seconds.length(), 4))).append("/1000" )
.toString();
}
public static void dumpExif(final String filename) throws IOException {
final ExifInterface exif = new ExifInterface(filename);
Log.d(TAG, "image width: " + exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, -1));
Log.d(TAG, "image length: " + exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, -1));
Log.d(TAG, "orientation: " + exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1));
Log.d(TAG, "datetime: " + exif.getAttribute(ExifInterface.TAG_DATETIME));
Log.d(TAG, "make: " + exif.getAttribute(ExifInterface.TAG_MAKE));
Log.d(TAG, "model: " + exif.getAttribute(ExifInterface.TAG_MODEL));
Log.d(TAG, "white balance: " + exif.getAttributeInt(ExifInterface.TAG_WHITE_BALANCE, -1));
Log.d(TAG, "flash: " + exif.getAttributeInt(ExifInterface.TAG_FLASH, -1));
Log.d(TAG, "gps latitude ref: " + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF));
Log.d(TAG, "gps latitude: " + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)); // ??
Log.d(TAG, "gps longitude ref: " + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF));
Log.d(TAG, "gps longitude: " + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)); // ??
Log.d(TAG, "gps altitude ref: " + exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF));
Log.d(TAG, "gps altitude: " + exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE)); // ??
Log.d(TAG, "gps datestamp: " + exif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP));
Log.d(TAG, "gps timestamp: " + exif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP));
}
}
Java Source Code List com.af.experiments.FxCameraApp.FilterAdapter.java com.af.experiments.FxCameraApp.MyActivity.java com.af.experiments.FxCameraApp.Utils.BitmapFactoryUtils.java com.af.experiments.FxCameraApp.Utils.ExifUtils.java com.af.experiments.FxCameraApp.Utils.Fps.java com.af.experiments.FxCameraApp.Utils.LogWriter.java com.af.experiments.FxCameraApp.Utils.OpenGlUtils.java com.af.experiments.FxCameraApp.View.CameraView.java com.af.experiments.FxCameraApp.View.DefaultPreview.java com.af.experiments.FxCameraApp.View.GlPreview.java com.af.experiments.FxCameraApp.View.PreviewTexture.java com.af.experiments.FxCameraApp.camera.CameraHelperBase.java com.af.experiments.FxCameraApp.camera.CameraHelperCupcake.java com.af.experiments.FxCameraApp.camera.CameraHelperDonut.java com.af.experiments.FxCameraApp.camera.CameraHelperEclair.java com.af.experiments.FxCameraApp.camera.CameraHelperFactory.java com.af.experiments.FxCameraApp.camera.CameraHelperFroyo.java com.af.experiments.FxCameraApp.camera.CameraHelperGingerbread.java com.af.experiments.FxCameraApp.camera.CameraHelperHonycomb.java com.af.experiments.FxCameraApp.camera.CameraHelperICS.java com.af.experiments.FxCameraApp.camera.CameraHelper.java com.af.experiments.FxCameraApp.display.DisplayHelperBase.java com.af.experiments.FxCameraApp.display.DisplayHelperFactory.java com.af.experiments.FxCameraApp.display.DisplayHelperFroyo.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycombMR2.java com.af.experiments.FxCameraApp.display.DisplayHelperHoneycomb.java com.af.experiments.FxCameraApp.display.DisplayHelper.java com.af.experiments.FxCameraApp.ogles.DefaultConfigChooser.java com.af.experiments.FxCameraApp.ogles.DefaultContextFactory.java com.af.experiments.FxCameraApp.ogles.DefaultWindowSurfaceFactory.java com.af.experiments.FxCameraApp.ogles.EGLLogWrapper.java com.af.experiments.FxCameraApp.ogles.GLES20ConfigChooser.java com.af.experiments.FxCameraApp.ogles.GLES20ContextFactory.java com.af.experiments.FxCameraApp.ogles.GlImageBitmapTexture.java com.af.experiments.FxCameraApp.ogles.GlImageResourceTexture.java com.af.experiments.FxCameraApp.ogles.GlImageTexture.java com.af.experiments.FxCameraApp.ogles.GlPreviewTextureFactory.java com.af.experiments.FxCameraApp.ogles.GlSurfaceTexture.java com.af.experiments.FxCameraApp.ogles.GlTextureView.java com.af.experiments.FxCameraApp.ogles.PixelBuffer.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperBase.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperFactory.java com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelper.java com.af.experiments.FxCameraApp.ogles.Texture.java com.af.experiments.FxCameraApp.renderer.GLES20FramebufferObject.java com.af.experiments.FxCameraApp.renderer.GlFrameBufferObjectRenderer.java com.af.experiments.FxCameraApp.renderer.MainRenderer.java com.af.experiments.FxCameraApp.shaders.GlBilateralShader.java com.af.experiments.FxCameraApp.shaders.GlBoxBlurShader.java com.af.experiments.FxCameraApp.shaders.GlBulgeDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlCGAColorspaceShader.java com.af.experiments.FxCameraApp.shaders.GlColorInvertShader.java com.af.experiments.FxCameraApp.shaders.GlColorMatrixShader.java com.af.experiments.FxCameraApp.shaders.GlColorPackingShader.java com.af.experiments.FxCameraApp.shaders.GlConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlEmbossShader.java com.af.experiments.FxCameraApp.shaders.GlFalseColorShader.java com.af.experiments.FxCameraApp.shaders.GlFastBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGaussianBlurShader.java com.af.experiments.FxCameraApp.shaders.GlGlassSphereShader.java com.af.experiments.FxCameraApp.shaders.GlGrayScaleShader.java com.af.experiments.FxCameraApp.shaders.GlHarrisCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlHazeShader.java com.af.experiments.FxCameraApp.shaders.GlMonochromeShader.java com.af.experiments.FxCameraApp.shaders.GlNobleCornerDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlPerlinNoiseShader.java com.af.experiments.FxCameraApp.shaders.GlPinchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolarPixellateShader.java com.af.experiments.FxCameraApp.shaders.GlPolkaDotShader.java com.af.experiments.FxCameraApp.shaders.GlPosterizeShader.java com.af.experiments.FxCameraApp.shaders.GlPreviewShader.java com.af.experiments.FxCameraApp.shaders.GlSepiaShader.java com.af.experiments.FxCameraApp.shaders.GlShaderGroup.java com.af.experiments.FxCameraApp.shaders.GlShader.java com.af.experiments.FxCameraApp.shaders.GlSharpenShader.java com.af.experiments.FxCameraApp.shaders.GlShiTomasiFeatureDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSobelEdgeDetectionShader.java com.af.experiments.FxCameraApp.shaders.GlSphereRefractionShader.java com.af.experiments.FxCameraApp.shaders.GlStretchDistortionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3ConvolutionShader.java com.af.experiments.FxCameraApp.shaders.GlThreex3TextureSamplingShader.java com.af.experiments.FxCameraApp.shaders.GlToneShader.java com.af.experiments.FxCameraApp.shaders.GlTwoInputShader.java com.af.experiments.FxCameraApp.shaders.GlVignetteShader.java com.af.experiments.FxCameraApp.shaders.GlWeakPixelInclusionShader.java com.af.experiments.FxCameraApp.shaders.GlWhiteBalanceShader.java com.af.experiments.FxCameraApp.shaders.GlXRayShader.java com.af.experiments.FxCameraApp.shaders.GlXYDerivativeShader.java com.af.experiments.FxCameraApp.shaders.fx.GlLutShader.java