List of usage examples for android.media ExifInterface getAttributeInt
public int getAttributeInt(String tag, int defaultValue)
From source file:com.dastardlylabs.ti.ocrdroid.OcrdroidModule.java
@Kroll.method @SuppressWarnings("rawtypes") public String ocr(HashMap _config) { assert (_config != null); String dataParentPath = getTessDataDirectory().getAbsolutePath(), //= (String) _config.get("dataParent"), imagePath = StorageHelper.stripFileUri((String) _config.get("image")), language = (String) _config.get("lang"); try {//from w w w. j ava 2 s . c o m if (!tessDataExists()) unpackTessData(); } catch (Exception e) { // catch failure and bubble up failure message and options // else continue. } Log.d(LCAT, "ocr called"); Log.d(LCAT, "Setting parent directory for tessdata as DATAPATH".replace("DATAPATH", dataParentPath /*DATA_PATH*/)); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options); //bitmap.getConfig() try { ExifInterface exif = new ExifInterface(imagePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Log.v(LCAT, "Orient: " + exifOrientation); int rotate = 0; switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; } Log.v(LCAT, "Rotation: " + rotate); if (rotate != 0) { // Getting width & height of the given image. int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting pre rotate Matrix mtx = new Matrix(); mtx.preRotate(rotate); // Rotating Bitmap bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false); // tesseract req. ARGB_8888 bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); } } catch (IOException e) { Log.e(LCAT, "Rotate or coversion failed: " + e.toString()); } // ImageView iv = (ImageView) findViewById(R.id.image); // iv.setImageBitmap(bitmap); // iv.setVisibility(View.VISIBLE); Log.v(LCAT, "Before baseApi"); TessBaseAPI baseApi = new TessBaseAPI(); baseApi.setDebug(true); baseApi.init(dataParentPath /*DATA_PATH*/, language); baseApi.setImage(bitmap); //baseApi.get String recognizedText = baseApi.getUTF8Text(); baseApi.end(); Log.v(LCAT, "OCR Result: " + recognizedText); // clean up and show if (language.equalsIgnoreCase("eng")) { recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " "); } return recognizedText.trim(); }
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 {//w w w. ja va 2 s . co m 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:om.sstvencoder.MainActivity.java
public int getOrientation(ContentResolver resolver, Uri uri) { int orientation = 0; try {// www .j a va 2s .c o m Cursor cursor = resolver.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.moveToFirst()) orientation = cursor.getInt(0); cursor.close(); } catch (Exception ignore) { try { ExifInterface exif = new ExifInterface(uri.getPath()); orientation = Utility.convertToDegrees(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)); } catch (Exception ex) { showOrientationErrorMessage(uri, ex); } } return orientation; }
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. j av 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.example.photoremark.MainActivity.java
/** * ?exif?/* w ww . jav a2 s. co m*/ * * @param path * @return */ public int getPictureDegree(String path) { int degree = 0; try { ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:com.daiv.android.twitter.services.SendTweet.java
public Bitmap getBitmapToSend(Uri uri, Context context) throws IOException { InputStream input = context.getContentResolver().openInputStream(uri); int reqWidth = 750; int reqHeight = 750; byte[] byteArr = new byte[0]; byte[] buffer = new byte[1024]; int len;/*from w w w. j a v a 2 s. co m*/ int count = 0; try { while ((len = input.read(buffer)) > -1) { if (len != 0) { if (count + len > byteArr.length) { byte[] newbuf = new byte[(count + len) * 2]; System.arraycopy(byteArr, 0, newbuf, 0, count); byteArr = newbuf; } System.arraycopy(buffer, 0, byteArr, count, len); count += len; } } final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(byteArr, 0, count, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inPurgeable = true; options.inInputShareable = true; options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options); ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context)); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); return rotateBitmap(b, orientation); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.cpjd.roblu.ui.images.ImageGalleryActivity.java
/** * Receives the picture that was taken by the user * @param requestCode the request code of the child activity * @param resultCode the result code of the child activity * @param data the picture that was taken *///from w w w . j a va 2s . com @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constants.GENERAL && resultCode == FragmentActivity.RESULT_OK) { // fetch file from storage Bitmap bitmap = BitmapFactory.decodeFile(tempPictureFile.getPath()); // fix rotation try { ExifInterface ei = new ExifInterface(tempPictureFile.getPath()); 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; default: break; } } catch (IOException e) { Log.d("RBS", "Failed to remove EXIF rotation data from the picture."); } /* * Convert the image into a byte[] and save it to the gallery */ // Convert the bitmap to a byte array ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream); byte[] array = stream.toByteArray(); int newID = new IO(getApplicationContext()).savePicture(eventID, array); // Add the image to the current array if (IMAGES == null) IMAGES = new ArrayList<>(); IMAGES.add(array); // save the ID to the gallery for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs() == null) { ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .setPictureIDs(new ArrayList<Integer>()); } ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() .add(newID); break; } } TeamViewer.team.setLastEdit(System.currentTimeMillis()); new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); imageGalleryAdapter.notifyDataSetChanged(); } /* * User edited an image */ else if (resultCode == Constants.IMAGE_EDITED) { TeamViewer.team.setLastEdit(System.currentTimeMillis()); /* * Update the image in the gallery */ for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs() == null) { ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .setPictureIDs(new ArrayList<Integer>()); } ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() .add(new IO(getApplicationContext()).savePicture(eventID, IMAGES.get(data.getIntExtra("position", 0)))); break; } } new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); imageGalleryAdapter.notifyDataSetChanged(); } /* * User deleted an image */ else if (resultCode == Constants.IMAGE_DELETED) { // Remove the image from the gallery ID list for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) { if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) { int pictureID = ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)) .getPictureIDs().remove(data.getIntExtra("position", 0)); // delete from file system new IO(getApplicationContext()).deletePicture(eventID, pictureID); break; } } IMAGES.remove(data.getIntExtra("position", 0)); imageGalleryAdapter.notifyDataSetChanged(); TeamViewer.team.setLastEdit(System.currentTimeMillis()); new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team); } }
From source file:com.liwn.zzl.markbit.DrawOptionsMenuActivity.java
private Uri rotateNormal(Uri uri) throws IOException { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotationInDegrees = exifToDegrees(rotation); Matrix matrix = new Matrix(); if (rotation != 0) { matrix.preRotate(rotationInDegrees); }//from w ww . j a v a 2 s .com Bitmap srcBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri); Bitmap adjustedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, MarkBitApplication.BIT_LCD_WIDTH, MarkBitApplication.BIT_LCD_HEIGHT, matrix, true); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), adjustedBitmap, "Title", null); return Uri.parse(path); }
From source file:com.m2dl.mini_projet.mini_projet_android.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { Uri selectedImage = imageUri; getContentResolver().notifyChange(selectedImage, null); ContentResolver cr = getContentResolver(); try { myBitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage); myBitmap = BitmapUtil.resize(myBitmap); imageFilePath = imageUri.getPath(); ExifInterface exif = new ExifInterface(imageFilePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: myBitmap = BitmapUtil.rotateImage(myBitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: myBitmap = BitmapUtil.rotateImage(myBitmap, 180); break; }/* w w w .j a va 2s. c om*/ String dialogTitle; String dialogMessage; if (!isGPSOn) { dialogTitle = "Golocalisation GPS..."; dialogMessage = "Veuillez activer votre GPS puis patienter pendant la golocalisation"; } else { dialogTitle = "Golocalisation GPS..."; dialogMessage = "Veuillez patienter pendant la golocalisation"; } final ProgressDialog progDialog = ProgressDialog.show(MainActivity.this, dialogTitle, dialogMessage, true); new Thread() { public void run() { try { while (coordLat.equals(0.0d) && coordLong.equals(0.0d)) ; FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); DialogFragment newFragment = PhotoDialogFragment.newInstance(myBitmap, coordLat, coordLong, imageFilePath); newFragment.show(ft, "dialog"); } catch (Exception e) { Log.e(TAG, e.getMessage()); } progDialog.dismiss(); } }.start(); } catch (Exception e) { Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show(); Log.e("Camera", e.toString()); } } } }
From source file:openscience.crowdsource.video.experiments.MainActivity.java
/** * Rotate an image if required./* w w w .j ava 2 s. c o m*/ * * @param selectedImagePath Image URI * @return The resulted Bitmap after manipulation */ private static int getImageDegree(String selectedImagePath) { ExifInterface ei = null; try { ei = new ExifInterface(selectedImagePath); } catch (IOException e) { AppLogger.logMessage("Error image could not be rotated " + e.getLocalizedMessage()); } int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return 0; } }