List of usage examples for android.media ExifInterface ORIENTATION_NORMAL
int ORIENTATION_NORMAL
To view the source code for android.media ExifInterface ORIENTATION_NORMAL.
Click Source Link
From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {//from w w w .j a va2s . 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.wots.lutmaar.CustomView.imagechooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {// ww w .j av a2 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:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {/*from w w w . j av a 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 (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:ir.rasen.charsoo.controller.image_loader.core.decode.BaseImageDecoder.java
protected ExifInfo defineExifOrientation(String imageUri) { int rotation = 0; boolean flip = false; try {/*from ww w .j a v a 2 s .c om*/ ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri)); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = true; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = true; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { L.w("Can't read EXIF tags from file [%s]", imageUri); } return new ExifInfo(rotation, flip); }
From source file:kr.wdream.ui.Components.AvatarUpdater.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 13) { PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity()); int orientation = 0; try { ExifInterface ei = new ExifInterface(currentPicturePath); int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exif) { case ExifInterface.ORIENTATION_ROTATE_90: orientation = 90;//w w w .jav a2 s. c om break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = 270; break; } } catch (Exception e) { FileLog.e("tmessages", e); } final ArrayList<Object> arrayList = new ArrayList<>(); arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false)); PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 1, new PhotoViewer.EmptyPhotoViewerProvider() { @Override public void sendButtonPressed(int index) { String path = null; MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList .get(0); if (photoEntry.imagePath != null) { path = photoEntry.imagePath; } else if (photoEntry.path != null) { path = photoEntry.path; } Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true); processBitmap(bitmap); } @Override public boolean allowCaption() { return false; } }, null); AndroidUtilities.addMediaToGallery(currentPicturePath); currentPicturePath = null; } else if (requestCode == 14) { if (data == null || data.getData() == null) { return; } startCrop(null, data.getData()); } } }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
@SuppressWarnings("unused") private String reporteds(String path) { ExifInterface exif = null;//from ww w.j a v a 2 s . c o m try { exif = new ExifInterface(path); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); } else if (orientation == 3) { matrix.postRotate(180); } else if (orientation == 8) { matrix.postRotate(270); } if (path != null) { if (path.contains("http")) { try { URL url = new URL(path); HttpGet httpRequest = null; httpRequest = new HttpGet(url.toURI()); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream input = bufHttpEntity.getContent(); Bitmap bitmap = BitmapFactory.decodeStream(input); input.close(); return getPath(bitmap); } catch (MalformedURLException e) { Log.e("ImageActivity", "bad url", e); } catch (Exception e) { Log.e("ImageActivity", "io error", e); } } else { Options options = new Options(); options.inSampleSize = 2; options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), srcBgId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateInSampleSize(options, w, h); Bitmap unbgbtmp = BitmapFactory.decodeResource(context.getResources(), srcBgId, options); Bitmap unrlbtmp = ScalingUtilities.decodeFile(path, w, h, ScalingLogic.FIT); unrlbtmp.recycle(); Bitmap rlbtmp = null; if (unrlbtmp != null) { rlbtmp = ScalingUtilities.createScaledBitmap(unrlbtmp, w, h, ScalingLogic.FIT); } if (unbgbtmp != null && rlbtmp != null) { Bitmap bgbtmp = ScalingUtilities.createScaledBitmap(unbgbtmp, w, h, ScalingLogic.FIT); Bitmap newscaledBitmap = ProcessingBitmapTwo(bgbtmp, rlbtmp); unbgbtmp.recycle(); return getPath(newscaledBitmap); } } } return path; }
From source file:com.daiv.android.twitter.services.SendTweet.java
public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) { Log.v("Test_composing_image", "rotation: " + orientation); try {/*w w w .j a v a 2 s . c om*/ Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:com.almalence.opencam.PluginManagerBase.java
protected PluginManagerBase() { pluginList = new Hashtable<String, Plugin>(); processingPluginList = new HashMap<Long, Plugin>(); sharedMemory = new Hashtable<String, String>(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) createRAWCaptureResultHashtable(); activeVF = new ArrayList<String>(); // activeFilter = new ArrayList<String>(); listVF = new ArrayList<Plugin>(); listCapture = new ArrayList<Plugin>(); listProcessing = new ArrayList<Plugin>(); // listFilter = new ArrayList<Plugin>(); listExport = new ArrayList<Plugin>(); createPlugins();/*from w w w . ja va 2s.com*/ // parsing configuration file to setup modes parseConfig(); exifOrientationMap = new HashMap<Integer, Integer>() { { put(0, ExifInterface.ORIENTATION_NORMAL); put(90, ExifInterface.ORIENTATION_ROTATE_90); put(180, ExifInterface.ORIENTATION_ROTATE_180); put(270, ExifInterface.ORIENTATION_ROTATE_270); } }; }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static Bitmap rotate(String path, Bitmap bm) { if (bm == null) { return null; }/* ww w .j ava2 s. c o m*/ Bitmap result = bm; int ori = ExifInterface.ORIENTATION_NORMAL; try { ExifInterface ei = new ExifInterface(path); ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (Exception e) { //simply fallback to normal orientation AQUtility.debug(e); } if (ori > 0) { Matrix matrix = getRotateMatrix(ori); result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight()); AQUtility.debug("after", result.getWidth() + ":" + result.getHeight()); if (bm != result) { bm.recycle(); } } return result; }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private static Bitmap rotate(String path, Bitmap bm) { if (bm == null) return null; Bitmap result = bm;/* www .j a v a2s.co m*/ int ori = ExifInterface.ORIENTATION_NORMAL; try { ExifInterface ei = new ExifInterface(path); ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (Exception e) { //simply fallback to normal orientation AQUtility.debug(e); } if (ori > 0) { Matrix matrix = getRotateMatrix(ori); result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight()); AQUtility.debug("after", result.getWidth() + ":" + result.getHeight()); if (bm != result) { bm.recycle(); } } return result; }