List of usage examples for android.media ExifInterface getAttributeInt
public int getAttributeInt(String tag, int defaultValue)
From source file:com.snappy.CameraCropActivity.java
protected void onPhotoTaken(final String path) { String fileName = Uri.parse(path).getLastPathSegment(); mFilePath = CameraCropActivity.this.getExternalCacheDir() + "/" + fileName; if (!path.equals(mFilePath)) { copy(new File(path), new File(mFilePath)); }//from ww w.ja v a 2 s . c o m new AsyncTask<String, Void, byte[]>() { boolean loadingFailed = false; @Override protected byte[] doInBackground(String... params) { try { if (!path.equals(mFilePath)) { copy(new File(path), new File(mFilePath)); } if (params == null) return null; File f = new File(params[0]); ExifInterface exif = new ExifInterface(f.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { angle = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { angle = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { angle = 270; } Matrix mat = new Matrix(); mat.postRotate(angle); BitmapFactory.Options optionsMeta = new BitmapFactory.Options(); optionsMeta.inJustDecodeBounds = true; BitmapFactory.decodeFile(f.getAbsolutePath(), optionsMeta); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = BitmapManagement.calculateInSampleSize(optionsMeta, 640, 640); options.inPurgeable = true; options.inInputShareable = true; mBitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, options); mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), mat, true); _scaleBitmap(); return null; } catch (Exception ex) { loadingFailed = true; finish(); } return null; } @Override protected void onPostExecute(byte[] result) { super.onPostExecute(result); if (null != mBitmap) { mImageView.setImageBitmap(mBitmap); mImageView.setScaleType(ScaleType.MATRIX); translateMatrix.setTranslate(-(mBitmap.getWidth() - crop_container_size) / 2f, -(mBitmap.getHeight() - crop_container_size) / 2f); mImageView.setImageMatrix(translateMatrix); matrix = translateMatrix; } } }.execute(mFilePath); }
From source file:org.appcelerator.titanium.view.TiDrawableReference.java
private int getOrientation() { String path = null;// w w w . j a v a 2s.c o m int orientation = 0; if (isTypeBlob() && blob != null) { path = blob.getNativePath(); } else if (isTypeFile() && file != null) { path = file.getNativeFile().getAbsolutePath(); } else { InputStream is = getInputStream(); if (is != null) { File file = TiFileHelper.getInstance().getTempFileFromInputStream(is, "EXIF-TMP", true); path = file.getAbsolutePath(); } } try { if (path == null) { Log.e(TAG, "Path of image file could not determined. Could not create an exifInterface from an invalid path."); return 0; } // Remove path prefix if (path.startsWith(FILE_PREFIX)) { path = path.replaceFirst(FILE_PREFIX, ""); } ExifInterface exifInterface = new ExifInterface(path); orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { orientation = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { orientation = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { orientation = 270; } else { orientation = 0; } } catch (IOException e) { Log.e(TAG, "Error creating exifInterface, could not determine orientation.", Log.DEBUG_MODE); } return orientation; }
From source file:com.sim2dial.dialer.ChatFragment.java
private void uploadAndSendImage(final String filePath, final Bitmap image, final ImageSize size) { uploadLayout.setVisibility(View.VISIBLE); textLayout.setVisibility(View.GONE); uploadThread = new Thread(new Runnable() { @Override//from www. j a v a 2 s . c o m public void run() { Bitmap bm = null; String url = null; if (!uploadThread.isInterrupted()) { if (filePath != null) { bm = BitmapFactory.decodeFile(filePath); if (bm != null && size != ImageSize.REAL) { int pixelsMax = size == ImageSize.SMALL ? SIZE_SMALL : size == ImageSize.MEDIUM ? SIZE_MEDIUM : SIZE_LARGE; if (bm.getWidth() > bm.getHeight() && bm.getWidth() > pixelsMax) { bm = Bitmap.createScaledBitmap(bm, pixelsMax, (pixelsMax * bm.getHeight()) / bm.getWidth(), false); } else if (bm.getHeight() > bm.getWidth() && bm.getHeight() > pixelsMax) { bm = Bitmap.createScaledBitmap(bm, (pixelsMax * bm.getWidth()) / bm.getHeight(), pixelsMax, false); } } } else if (image != null) { bm = image; } } // Rotate the bitmap if possible/needed, using EXIF data try { if (filePath != null) { ExifInterface exif = new ExifInterface(filePath); int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); Matrix matrix = new Matrix(); if (pictureOrientation == 6) { matrix.postRotate(90); } else if (pictureOrientation == 3) { matrix.postRotate(180); } else if (pictureOrientation == 8) { matrix.postRotate(270); } bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } } catch (Exception e) { e.printStackTrace(); } ByteArrayOutputStream outStream = new ByteArrayOutputStream(); if (bm != null) { bm.compress(CompressFormat.JPEG, COMPRESSOR_QUALITY, outStream); } if (!uploadThread.isInterrupted() && bm != null) { url = uploadImage(filePath, bm, COMPRESSOR_QUALITY, outStream.size()); File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name)); file.delete(); } if (!uploadThread.isInterrupted()) { final Bitmap fbm = bm; final String furl = url; mHandler.post(new Runnable() { @Override public void run() { uploadLayout.setVisibility(View.GONE); textLayout.setVisibility(View.VISIBLE); progressBar.setProgress(0); if (furl != null) { sendImageMessage(furl, fbm); } else { Toast.makeText(getActivity(), getString(R.string.error), Toast.LENGTH_LONG).show(); } } }); } } }); uploadThread.start(); }
From source file:org.linphone.ContactEditorFragment.java
private void editContactPicture(final String filePath, final Bitmap image) { int SIZE_SMALL = 256; int COMPRESSOR_QUALITY = 100; Bitmap bitmapUnknown = BitmapFactory.decodeResource(getResources(), R.drawable.avatar); Bitmap bm = null;//from ww w. ja va 2 s .c om if (filePath != null) { int pixelsMax = SIZE_SMALL; //Resize image bm = BitmapFactory.decodeFile(filePath); if (bm != null) { if (bm.getWidth() > bm.getHeight() && bm.getWidth() > pixelsMax) { bm = Bitmap.createScaledBitmap(bm, 256, 256, false); } } } else if (image != null) { bm = image; } // Rotate the bitmap if possible/needed, using EXIF data try { if (imageToUploadUri != null && filePath != null) { ExifInterface exif = new ExifInterface(filePath); int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); Matrix matrix = new Matrix(); if (pictureOrientation == 6) { matrix.postRotate(90); } else if (pictureOrientation == 3) { matrix.postRotate(180); } else if (pictureOrientation == 8) { matrix.postRotate(270); } bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } } catch (Exception e) { e.printStackTrace(); } Bitmap bitmapRounded; if (bm != null) { bitmapRounded = Bitmap.createScaledBitmap(bm, bitmapUnknown.getWidth(), bitmapUnknown.getWidth(), false); Canvas canvas = new Canvas(bitmapRounded); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(bitmapRounded, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); canvas.drawCircle(bitmapRounded.getWidth() / 2 + 0.7f, bitmapRounded.getHeight() / 2 + 0.7f, bitmapRounded.getWidth() / 2 + 0.1f, paint); contactPicture.setImageBitmap(bitmapRounded); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, COMPRESSOR_QUALITY, outStream); photoToAdd = outStream.toByteArray(); } }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
@SuppressWarnings("unused") private String reporteds(String path) { ExifInterface exif = null; try {/* w ww .java2s. c o m*/ 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.tealeaf.TeaLeaf.java
protected void onActivityResult(int request, int result, Intent data) { super.onActivityResult(request, result, data); PluginManager.callAll("onActivityResult", request, result, data); logger.log("GOT ACTIVITY RESULT WITH", request, result); switch (request) { case PhotoPicker.CAPTURE_IMAGE: if (result == RESULT_OK) { EventQueue.pushEvent(new PhotoBeginLoadedEvent()); Bitmap bmp = null;// w w w . j a va 2 s . c om if (data != null) { Bundle extras = data.getExtras(); //try and get bitmap off of intent if (extras != null) { bmp = (Bitmap) extras.get("data"); } } //try the large file on disk final File f = PhotoPicker.getCaptureImageTmpFile(); if (f != null && f.exists()) { new Thread(new Runnable() { public void run() { Bitmap bmp = null; String filePath = f.getAbsolutePath(); try { bmp = BitmapFactory.decodeFile(filePath); } catch (OutOfMemoryError e) { System.gc(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; bmp = BitmapFactory.decodeFile(filePath, options); } if (bmp != null) { try { File f = new File(filePath); ExifInterface exif = new ExifInterface(f.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (orientation != ExifInterface.ORIENTATION_NORMAL) { int rotateBy = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotateBy = ROTATE_90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotateBy = ROTATE_180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotateBy = ROTATE_270; break; } Bitmap rotatedBmp = rotateBitmap(bmp, rotateBy); if (rotatedBmp != bmp) { bmp.recycle(); } bmp = rotatedBmp; } } catch (Exception e) { logger.log(e); } f.delete(); if (bmp != null) { glView.getTextureLoader() .saveCameraPhoto(glView.getTextureLoader().getCurrentPhotoId(), bmp); glView.getTextureLoader().finishCameraPicture(); } else { glView.getTextureLoader().failedCameraPicture(); } } } }).start(); } else { glView.getTextureLoader().saveCameraPhoto(glView.getTextureLoader().getCurrentPhotoId(), bmp); glView.getTextureLoader().finishCameraPicture(); } } else { glView.getTextureLoader().failedCameraPicture(); } break; case PhotoPicker.PICK_IMAGE: if (result == RESULT_OK) { final Uri selectedImage = data.getData(); EventQueue.pushEvent(new PhotoBeginLoadedEvent()); String[] filePathColumn = { MediaColumns.DATA, MediaStore.Images.ImageColumns.ORIENTATION }; String _filepath = null; try { Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); _filepath = cursor.getString(columnIndex); columnIndex = cursor.getColumnIndex(filePathColumn[1]); int orientation = cursor.getInt(columnIndex); cursor.close(); } catch (Exception e) { } final String filePath = _filepath; new Thread(new Runnable() { public void run() { if (filePath == null) { BitmapFactory.Options options = new BitmapFactory.Options(); InputStream inputStream; Bitmap bmp = null; try { inputStream = getContentResolver().openInputStream(selectedImage); bmp = BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); } catch (Exception e) { logger.log(e); } if (bmp != null) { glView.getTextureLoader() .saveGalleryPicture(glView.getTextureLoader().getCurrentPhotoId(), bmp); glView.getTextureLoader().finishGalleryPicture(); } else { glView.getTextureLoader().failedGalleryPicture(); } } else { Bitmap bmp = null; try { bmp = BitmapFactory.decodeFile(filePath); } catch (OutOfMemoryError e) { System.gc(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; bmp = BitmapFactory.decodeFile(filePath, options); } if (bmp != null) { try { File f = new File(filePath); ExifInterface exif = new ExifInterface(f.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (orientation != ExifInterface.ORIENTATION_NORMAL) { int rotateBy = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotateBy = ROTATE_90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotateBy = ROTATE_180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotateBy = ROTATE_270; break; } Bitmap rotatedBmp = rotateBitmap(bmp, rotateBy); if (rotatedBmp != bmp) { bmp.recycle(); } bmp = rotatedBmp; } } catch (Exception e) { logger.log(e); } if (bmp != null) { glView.getTextureLoader() .saveGalleryPicture(glView.getTextureLoader().getCurrentPhotoId(), bmp); glView.getTextureLoader().finishGalleryPicture(); } else { glView.getTextureLoader().failedGalleryPicture(); } } } } }).start(); } else { glView.getTextureLoader().failedGalleryPicture(); } break; } }
From source file:com.klinker.android.twitter.activities.profile_viewer.ProfilePager.java
private Bitmap getBitmapToSend(Uri uri) throws FileNotFoundException, IOException { InputStream input = getContentResolver().openInputStream(uri); BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options(); onlyBoundsOptions.inJustDecodeBounds = true; onlyBoundsOptions.inDither = true;//optional onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional BitmapFactory.decodeStream(input, null, onlyBoundsOptions); input.close();// w w w . j av a 2 s .co m if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1)) return null; int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth; double ratio = (originalSize > 1000) ? (originalSize / 1000) : 1.0; BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio); bitmapOptions.inDither = true;//optional bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; input = this.getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); input.close(); return bitmap; }
From source file:com.klinker.android.twitter.ui.profile_viewer.ProfilePager.java
private Bitmap getBitmapToSend(Uri uri) throws FileNotFoundException, IOException { InputStream input = getContentResolver().openInputStream(uri); BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options(); onlyBoundsOptions.inJustDecodeBounds = true; onlyBoundsOptions.inDither = true;//optional onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional BitmapFactory.decodeStream(input, null, onlyBoundsOptions); input.close();/* w w w. j a v a 2s . c o m*/ if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1)) return null; int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth; double ratio = (originalSize > 500) ? (originalSize / 500) : 1.0; BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio); bitmapOptions.inDither = true;//optional bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; input = this.getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); input.close(); return rotateBitmap(bitmap, orientation); }
From source file:org.egov.android.view.activity.CreateComplaintActivity.java
public String compressImage(String fromfilepath, String tofilepath) { Bitmap scaledBitmap = null;/* w ww . j av a2 s . c o m*/ BitmapFactory.Options options = new BitmapFactory.Options(); // by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If // you try the use the bitmap here, you will get null. options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(fromfilepath, options); int actualHeight = options.outHeight; int actualWidth = options.outWidth; // max Height and width values of the compressed image is taken as 816x612 float maxHeight = 816.0f; float maxWidth = 612.0f; float imgRatio = actualWidth / actualHeight; float maxRatio = maxWidth / maxHeight; // width and height values are set maintaining the aspect ratio of the image if (actualHeight > maxHeight || actualWidth > maxWidth) { if (imgRatio < maxRatio) { imgRatio = maxHeight / actualHeight; actualWidth = (int) (imgRatio * actualWidth); actualHeight = (int) maxHeight; } else if (imgRatio > maxRatio) { imgRatio = maxWidth / actualWidth; actualHeight = (int) (imgRatio * actualHeight); actualWidth = (int) maxWidth; } else { actualHeight = (int) maxHeight; actualWidth = (int) maxWidth; } } // setting inSampleSize value allows to load a scaled down version of the original image options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight); // inJustDecodeBounds set to false to load the actual bitmap options.inJustDecodeBounds = false; // this options allow android to claim the bitmap memory if it runs low on memory options.inPurgeable = true; options.inInputShareable = true; options.inTempStorage = new byte[16 * 1024]; try { // load the bitmap from its path bmp = BitmapFactory.decodeFile(tofilepath, options); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } try { scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } float ratioX = actualWidth / (float) options.outWidth; float ratioY = actualHeight / (float) options.outHeight; float middleX = actualWidth / 2.0f; float middleY = actualHeight / 2.0f; Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(ratioX, ratioY, middleX, middleY); Canvas canvas = new Canvas(scaledBitmap); canvas.setMatrix(scaleMatrix); canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG)); String attrLatitute = null; String attrLatituteRef = null; String attrLONGITUDE = null; String attrLONGITUDEREf = null; // check the rotation of the image and display it properly ExifInterface exif; try { exif = new ExifInterface(fromfilepath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 3) { matrix.postRotate(180); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 8) { matrix.postRotate(270); Log.d("EXIF", "Exif: " + orientation); } attrLatitute = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); attrLatituteRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF); attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); attrLONGITUDEREf = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF); scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true); } catch (IOException e) { e.printStackTrace(); } FileOutputStream out = null; try { out = new FileOutputStream(tofilepath); // write the compressed bitmap at the destination specified by filename. scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out); ExifInterface exif2 = new ExifInterface(tofilepath); if (attrLatitute != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE, attrLatitute); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, attrLONGITUDE); } if (attrLatituteRef != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, attrLatituteRef); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, attrLONGITUDEREf); } exif2.saveAttributes(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tofilepath; }
From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java
private void previewCapturedImage() { try {//from www. ja v a 2 s . c o m Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ChnagedUri); if (bitmap != null) { ExifInterface ei = null; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { InputStream in = getContentResolver().openInputStream(ChnagedUri); ei = new ExifInterface(in); } else { ei = new ExifInterface(ChnagedUri.getPath()); } } catch (IOException e) { e.printStackTrace(); } if (ei != null) { int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: bitmap = rotateImage(bitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: bitmap = rotateImage(bitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: bitmap = rotateImage(bitmap, 270); break; } } Bitmap imageBitmap; imageBitmap = Bitmap.createScaledBitmap(AppUtils.resizeAndCropCenter(bitmap, 250, true), 250, 250, false); img_profile_square.setImageBitmap(imageBitmap); imagebaseProfilephoto = Generic.convertBitmapToByteStrem(imageBitmap); task = new ActivityProfile.UpdateProfilePhotoTask(); task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } } catch (IOException e) { e.printStackTrace(); //Set default image here } }