List of usage examples for android.media ExifInterface ExifInterface
public ExifInterface(InputStream inputStream) throws IOException
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Called when the camera view exits.//from ww w. ja va 2 s.c om * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; Log.d(LOG_TAG, "-z"); // If retrieving photo from library if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { Log.d(LOG_TAG, "-y"); if (resultCode == Activity.RESULT_OK) { Log.d(LOG_TAG, "-x"); Uri uri = intent.getData(); Log.d(LOG_TAG, "-w"); // If you ask for video or all media type you will automatically // get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { Log.d(LOG_TAG, "mediaType not PICTURE, so must be Video"); String metadataDateTime = ""; ExifInterface exif; try { exif = new ExifInterface(this.getRealPathFromURI(uri, this.cordova)); if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); } } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } Log.d(LOG_TAG, "before create thumbnail"); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( (new File(this.getRealPathFromURI(uri, this.cordova))).getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); Log.d(LOG_TAG, "after create thumbnail"); String mid = generateRandomMid(); try { String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); bitmap.compress(CompressFormat.JPEG, 100, foMedium); foMedium.flush(); foMedium.close(); bitmap.recycle(); System.gc(); JSONObject mediaFile = new JSONObject(); try { mediaFile.put("mid", mid); mediaFile.put("mediaType", "video"); mediaFile.put("filePath", filePathMedium); mediaFile.put("filePathMedium", filePathMedium); mediaFile.put("filePathThumb", filePathMedium); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); String absolutePath = (new File(this.getRealPathFromURI(uri, this.cordova))) .getAbsolutePath(); mediaFile.put("fileExt", absolutePath.substring(absolutePath.lastIndexOf(".") + 1)); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } } catch (JSONException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } Log.d(LOG_TAG, "mediafile at 638" + mediaFile.toString()); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); new UploadVideoToS3Task().execute(new File(this.getRealPathFromURI(uri, this.cordova)), this.callbackContext, mid, mediaFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } else { String imagePath = this.getRealPathFromURI(uri, this.cordova); String mimeType = FileUtils.getMimeType(imagePath); // If we don't have a valid image so quit. if (imagePath == null || mimeType == null || !(mimeType.equalsIgnoreCase("image/jpeg") || mimeType.equalsIgnoreCase("image/png"))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } String mid = generateRandomMid(); Log.d(LOG_TAG, "a"); JSONObject mediaFile = new JSONObject(); Log.d(LOG_TAG, "b"); try { FileInputStream fi = new FileInputStream(imagePath); Bitmap bitmap = BitmapFactory.decodeStream(fi); fi.close(); Log.d(LOG_TAG, "z1"); // try to get exif data ExifInterface exif = new ExifInterface(imagePath); Log.d(LOG_TAG, "z2"); JSONObject metadataJson = new JSONObject(); Log.d(LOG_TAG, "z3"); /* JSONObject latlng = new JSONObject(); String lat = "0"; String lng = "0"; if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) { lat = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); } if (exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) { lng = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); } latlng.put("lat", lat); latlng.put("lng", lng); Log.d(LOG_TAG, "z4"); metadataJson.put("locationData", latlng); */ String metadataDateTime = ""; if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); JSONObject exifWrapper = new JSONObject(); exifWrapper.put("DateTimeOriginal", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); exifWrapper.put("DateTimeDigitized", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); Log.d(LOG_TAG, "z5"); metadataJson.put("Exif", exifWrapper); } Log.d(LOG_TAG, "z6"); Log.d(LOG_TAG, "metadataJson: " + metadataJson.toString()); Log.d(LOG_TAG, "metadataDateTime: " + metadataDateTime.toString()); if (exif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) { int o = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION)); Log.d(LOG_TAG, "z7"); if (o == ExifInterface.ORIENTATION_NORMAL) { rotate = 0; } else if (o == ExifInterface.ORIENTATION_ROTATE_90) { rotate = 90; } else if (o == ExifInterface.ORIENTATION_ROTATE_180) { rotate = 180; } else if (o == ExifInterface.ORIENTATION_ROTATE_270) { rotate = 270; } else { rotate = 0; } Log.d(LOG_TAG, "z8"); Log.d(LOG_TAG, "rotate: " + rotate); // try to correct orientation if (rotate != 0) { Matrix matrix = new Matrix(); Log.d(LOG_TAG, "z9"); matrix.setRotate(rotate); Log.d(LOG_TAG, "z10"); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); Log.d(LOG_TAG, "z11"); } } Log.d(LOG_TAG, "c"); String filePath = this.getTempDirectoryPath(this.cordova.getActivity()) + "/econ_" + mid + ".jpg"; FileOutputStream foEcon = new FileOutputStream(filePath); fitInsideSquare(bitmap, 850).compress(CompressFormat.JPEG, 45, foEcon); foEcon.flush(); foEcon.close(); Log.d(LOG_TAG, "d"); String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); makeInsideSquare(bitmap, 320).compress(CompressFormat.JPEG, 55, foMedium); foMedium.flush(); foMedium.close(); Log.d(LOG_TAG, "e"); String filePathThumb = this.getTempDirectoryPath(this.cordova.getActivity()) + "/thumb_" + mid + ".jpg"; FileOutputStream foThumb = new FileOutputStream(filePathThumb); makeInsideSquare(bitmap, 175).compress(CompressFormat.JPEG, 55, foThumb); foThumb.flush(); foThumb.close(); bitmap.recycle(); System.gc(); Log.d(LOG_TAG, "f"); mediaFile.put("mid", mid); mediaFile.put("mediaType", "photo"); mediaFile.put("filePath", filePath); mediaFile.put("filePathMedium", filePath); mediaFile.put("filePathThumb", filePath); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); //mediaFile.put("metadataJson", metadataJson); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); Log.d(LOG_TAG, "g"); Log.d(LOG_TAG, "mediaFile " + mediaFile.toString()); new UploadFilesToS3Task().execute(new File(filePath), new File(filePathMedium), new File(filePathThumb), this.callbackContext, mid, mediaFile); Log.d(LOG_TAG, "h"); } catch (FileNotFoundException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } catch (IOException e1) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e1.getStackTrace().toString()); } catch (JSONException e2) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e2.getStackTrace().toString()); } /* if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova .getActivity() .getContentResolver() .query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // Create an ExifHelper to save the exif // data that is lost during compression String resizePath = this .getTempDirectoryPath(this.cordova .getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream( resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(this .getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); // The resized image is cached by the app in // order to get around this and not have to // delete your // application cache I'm adding the current // system time to the end of the file url. this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); */ } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:mobisocial.bento.ebento.ui.EditFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (DEBUG)//w w w . j a va2s .c o m Log.d(TAG, "requestCode: " + requestCode + ", resultCode: " + resultCode); if (resultCode == Activity.RESULT_OK) { try { File imageFile = null; if (requestCode == REQUEST_IMAGE_CAPTURE) { imageFile = JpgFileHelper.getTmpFile(); } else if (requestCode == REQUEST_GALLERY) { Uri uri = data.getData(); if (uri == null || uri.toString().length() == 0) { return; } if (DEBUG) Log.d(TAG, "data URI: " + uri.toString()); ContentResolver cr = getActivity().getContentResolver(); String[] columns = { MediaColumns.DATA, MediaColumns.DISPLAY_NAME }; Cursor c = cr.query(uri, columns, null, null, null); if (c != null && c.moveToFirst()) { if (c.getString(0) != null) { //regular processing for gallery files imageFile = new File(c.getString(0)); } else { final InputStream is = getActivity().getContentResolver().openInputStream(uri); imageFile = JpgFileHelper.saveTmpFile(is); is.close(); } } else if (uri.toString().startsWith("content://com.android.gallery3d.provider")) { // motorola xoom doesn't work for contentresolver even if the image comes from picasa. // So just adds the condition of startsWith... // See in detail : http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/ uri = Uri.parse( uri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d")); final InputStream is = getActivity().getContentResolver().openInputStream(uri); imageFile = JpgFileHelper.saveTmpFile(is); is.close(); } else { // http or https HttpURLConnection http = null; URL url = new URL(uri.toString()); http = (HttpURLConnection) url.openConnection(); http.setRequestMethod("GET"); http.connect(); final InputStream is = http.getInputStream(); imageFile = JpgFileHelper.saveTmpFile(is); is.close(); if (http != null) http.disconnect(); } } if (imageFile.exists() && imageFile.length() > 0) { if (DEBUG) Log.d(TAG, "imageFile exists=" + imageFile.exists() + " length=" + imageFile.length() + " path=" + imageFile.getPath()); float degrees = 0; try { ExifInterface exif = new ExifInterface(imageFile.getPath()); switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)) { case ExifInterface.ORIENTATION_ROTATE_90: degrees = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degrees = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degrees = 270; break; default: degrees = 0; break; } Log.d(TAG, exif.getAttribute(ExifInterface.TAG_ORIENTATION)); } catch (IOException e) { e.printStackTrace(); } sImageOrg = BitmapHelper.getResizedBitmap(imageFile, BitmapHelper.MAX_IMAGE_WIDTH, BitmapHelper.MAX_IMAGE_HEIGHT, degrees); mbImageChanged = true; // ImageView mImageView.setImageBitmap( BitmapHelper.getResizedBitmap(sImageOrg, mTargetWidth, mTargetHeight, 0)); mImageView.setVisibility(View.VISIBLE); mRootView.invalidate(); imageFile.delete(); JpgFileHelper.deleteTmpFile(); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java
private Bitmap getPortraitImage(String imagePath) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4;//from ww w . j ava 2s. c o m Bitmap photo = BitmapFactory.decodeFile(output.getPath(), options); float rotateAngle; try { ExifInterface exifInterface = new ExifInterface(imagePath); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotateAngle = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotateAngle = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotateAngle = 90; break; default: rotateAngle = 0; break; } return rotateImage(photo, rotateAngle); } catch (IOException e) { logger.e(e.getMessage()); return photo; } }
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)); }//w w w. j av a2 s. com 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.egov.android.view.activity.CreateComplaintActivity.java
private void _getLatAndLng(String imageUrl) { try {/*ww w. j av a 2 s .co m*/ double lat = 0.0; double lng = 0.0; ExifInterface exif = new ExifInterface(imageUrl); String attrLatitute = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); String attrLatituteRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF); String attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); String attrLONGITUDEREf = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF); if (attrLatitute == null && attrLONGITUDE == null) { return; } if (attrLatituteRef.equals("N")) { lat = convertToDegree(attrLatitute); } if (attrLONGITUDEREf.equals("E")) { lng = convertToDegree(attrLONGITUDE); } isCurrentLocation = false; _getCurrentLocation(lat, lng); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.bai.android.ui.OtherActivity.java
private static int getOrientationFromFile(String imagePath) { int orientation = ExifInterface.ORIENTATION_NORMAL; int rotation; // get orientation of file try {/*from ww w .j av a 2 s . c o m*/ ExifInterface exif = new ExifInterface(imagePath); orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { e.printStackTrace(); } // set the rotation from the file orientation switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; default: rotation = ExifInterface.ORIENTATION_NORMAL; break; } return rotation; }
From source file:com.stfalcon.contentmanager.ContentManager.java
/** * Some devices return wrong rotated image so we can fix it by this method *//*w w w . jav a2s. c om*/ public static void fixImageRatation(Uri uri, Bitmap realImage) { File pictureFile = new File(uri.getPath()); try { FileOutputStream fos = new FileOutputStream(pictureFile); ExifInterface exif = new ExifInterface(pictureFile.toString()); if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")) { realImage = rotate(realImage, 90); } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")) { realImage = rotate(realImage, 270); } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")) { realImage = rotate(realImage, 180); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } }
From source file:com.saulcintero.moveon.fragments.Summary1.java
private void pictureMarkers() { int picId = 0; areAnyPictures = false;//from www . j av a 2 s . co m if (folder.isDirectory()) { files = folder.list(); if (files.length > 0) { Arrays.sort(files); for (int i = 0; i < files.length; i++) { String[] splitFile = files[i].split("_"); if (splitFile[0].equals(String.valueOf(prefs.getInt("selected_practice", 0)))) { areAnyPictures = true; File imageFile = new File(file_path + files[i]); ExifInterface exif = null; try { exif = new ExifInterface(imageFile.getAbsolutePath()); float[] LatLong = MediaFunctionUtils.ShowExif(mContext, exif); if (LatLong != null) { addMarker(3, new GeoPoint(LatLong[0], LatLong[1]), MarkerTypes.PHOTO_MARKER.getTypes(), String.valueOf(picId), ""); picId++; } } catch (IOException e) { e.printStackTrace(); } } } if (areAnyPictures) markChosenPicture(markChosenPicturePosition); } } }
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;/*from ww w.j av a2s .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.mobantica.DriverItRide.activities.ActivityProfile.java
private void previewCapturedImage() { try {/*from ww w . j a v a2 s. c om*/ 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 } }