List of usage examples for android.media ExifInterface getAttribute
public String getAttribute(String tag)
From source file:com.oxgcp.photoList.PhotolistModule.java
@Kroll.method public KrollDict getExifData(String fileName) { try {//from w w w . j av a2 s.co m ExifInterface exif = new ExifInterface(fileName); HashMap<String, String> tag = new HashMap<String, String>(); tag.put("hasThumbnail", exif.hasThumbnail() ? "true" : null); tag.put("height", exif.getAttribute("ImageLength")); tag.put("width", exif.getAttribute("ImageWidth")); tag.put("alt", exif.getAttribute("GPSAltitude")); tag.put("altRef", exif.getAttribute("GPSAltitudeRef")); tag.put("lat", exif.getAttribute("GPSLatitude")); tag.put("latRef", exif.getAttribute("GPSLatitudeRef")); tag.put("lon", exif.getAttribute("GPSLongitude")); tag.put("lonRef", exif.getAttribute("GPSLongitudeRef")); tag.put("date", exif.getAttribute("GPSDateStamp")); tag.put("time", exif.getAttribute("GPSTimeStamp")); return new KrollDict(tag);//new JSONObject(tag).toString(); } catch (Exception e) { return null; } }
From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {//ww w . j a va 2 s . c o m ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (Config.DEBUG) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (Config.DEBUG) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (Config.DEBUG) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (Config.DEBUG) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {//from www . j a va 2s .c o m ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (/* TODO: DEBUG */ true) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (/* TODO: DEBUG */ true) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (/* TODO: DEBUG */ true) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }
From source file:com.example.lowviscam.GalleryActivity.java
/** * Generate the list of all coupons.//ww w . j av a 2 s.c o m * @return The list of coupons. * @throws IOException */ private List<Coupon> createAllCoupons() throws IOException { // TODO: Customize this list of coupons for your personal use. List<Coupon> coupons = new ArrayList<Coupon>(); File list[] = mediaStorageDir.listFiles(); for (int i = list.length - 1; i > -1; i--) { //Get text tag String tag = "NA"; try { ExifInterface exif = new ExifInterface(list[i].getPath()); tag = exif.getAttribute("UserComment"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } coupons.add(new Coupon(tag, list[i].getName())); } // You can add a title, subtitle, and a photo (in the assets directory). return coupons; }
From source file:com.example.lowviscam.GalleryActivity.java
private List<Coupon> createSearchedCoupons(String query) throws IOException { // TODO: Customize this list of coupons for your personal use. List<Coupon> coupons = new ArrayList<Coupon>(); numSearchResults = 0;//www. jav a 2s .c o m File list[] = mediaStorageDir.listFiles(); int j = 0; for (int i = list.length - 1; i > -1; i--) { //Get text tag String tag = "NA"; try { ExifInterface exif = new ExifInterface(list[i].getPath()); tag = exif.getAttribute("UserComment"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (tag.toLowerCase().contains(query.toLowerCase())) { coupons.add(new Coupon(tag, list[i].getName())); tagList[j] = tag; numSearchResults++; j++; } } // You can add a title, subtitle, and a photo (in the assets directory). return coupons; }
From source file:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {//w w w . ja v a2 s. c om ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (BuildConfig.DEBUG) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (BuildConfig.DEBUG) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (BuildConfig.DEBUG) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (BuildConfig.DEBUG) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }
From source file:com.wots.lutmaar.CustomView.imagechooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {/*from w w w.ja va 2 s . c o m*/ ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (BuildConfig.DEBUG) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (BuildConfig.DEBUG) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } /* if (scale == 1) bitmap = Bitmap.createScaledBitmap(bitmap, 240, 260, true);*/ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (BuildConfig.DEBUG) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (BuildConfig.DEBUG) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }
From source file:freed.viewer.screenslide.ScreenSlideFragment.java
private void processExif(final File file) { FreeDPool.Execute(new Runnable() { @Override//from w ww .j a v a 2s. c o m public void run() { try { final ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath()); iso.post(new Runnable() { @Override public void run() { try { shutter.setText("S:" + exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)); } catch (NullPointerException e) { shutter.setVisibility(View.GONE); } try { fnumber.setText("f~:" + exifInterface.getAttribute(ExifInterface.TAG_F_NUMBER)); } catch (NullPointerException e) { fnumber.setVisibility(View.GONE); } try { focal.setText("A:" + exifInterface.getAttribute(ExifInterface.TAG_APERTURE_VALUE)); } catch (NullPointerException e) { focal.setVisibility(View.GONE); } try { iso.setText( "ISO:" + exifInterface.getAttribute(ExifInterface.TAG_ISO_SPEED_RATINGS)); } catch (NullPointerException e) { iso.setVisibility(View.GONE); } } }); } catch (NullPointerException | IOException ex) { Log.d(TAG, "Failed to read Exif"); } } }); }
From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueA.java
/** * Check Image Orientation // w ww. j a v a2 s . c o m */ public void CheckOrient() { BitmapFactory.Options options = new BitmapFactory.Options(); // Resize is needed otherwize outofmemory exception options.inSampleSize = 6; //------------- read tmp file ------------------ Image_BMP = BitmapFactory.decodeFile(image_path_source_temp, options); // , options //---------------- find exif header -------- ExifInterface exif; String exifOrientation = "0"; // 0 = exif not working try { exif = new ExifInterface(image_path_source_temp); exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION); } catch (IOException e1) { e1.printStackTrace(); } //---------------- Resize --------------------- if (exifOrientation.equals("0")) { if (Image_BMP.getWidth() < Image_BMP.getHeight() && Image_BMP.getWidth() > 400) { Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 400, 640, true); // <- To sent } else if (Image_BMP.getWidth() > Image_BMP.getHeight() && Image_BMP.getWidth() > 640) { Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 640, 400, true); // <- To sent } } else { if (exifOrientation.equals("1") && Image_BMP.getWidth() > 640) { // normal Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 640, 400, true); // <- To sent } else if (exifOrientation.equals("6") && Image_BMP.getWidth() > 400) { // rotated 90 degrees // Rotate Matrix matrix = new Matrix(); int bmwidth = Image_BMP.getWidth(); int bmheight = Image_BMP.getHeight(); matrix.postRotate(90); Image_BMP = Bitmap.createBitmap(Image_BMP, 0, 0, bmwidth, bmheight, matrix, true); Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 400, 640, true); // <- To sent } } DisplayMetrics metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); //------------ now store as jpg over the temp jpg File imagef = new File(image_path_source_temp); try { Image_BMP.compress(Bitmap.CompressFormat.JPEG, 95, new FileOutputStream(imagef)); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
protected ImageInfo extractImageInfo(File file) { ImageInfo res = new ImageInfo(); ExifInterface exifInterface = null; try {// www.jav a 2 s.co m exifInterface = new ExifInterface(file.getPath()); } catch (IOException e) { Log.e(TAG, "extractImageInfo Could not read exif", e); } // Date String dateTimeStr = null; if (exifInterface != null) dateTimeStr = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); if (TextUtils.isEmpty(dateTimeStr)) { // No date in exif: use 'local' date res.dateTime = DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } else { res.dateTime = parseExifDateTime(dateTimeStr); if (res.dateTime == null) { // Date in exif could not be parsed: use 'local' date DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } } // Location float[] latLon = new float[2]; boolean latLonPresent = exifInterface != null && exifInterface.getLatLong(latLon); if (!latLonPresent) { // No location in exif: use 'local' location res.isLocalLocation = true; latLonPresent = getLatestLocalLocation(latLon); if (latLonPresent) res.location = reverseGeocode(latLon[0], latLon[1]); } else { res.location = reverseGeocode(latLon[0], latLon[1]); } if (res.location == null) { res.reverseGeocodeProblem = true; res.location = ""; } return res; }