Example usage for android.media ExifInterface ORIENTATION_UNDEFINED

List of usage examples for android.media ExifInterface ORIENTATION_UNDEFINED

Introduction

In this page you can find the example usage for android.media ExifInterface ORIENTATION_UNDEFINED.

Prototype

int ORIENTATION_UNDEFINED

To view the source code for android.media ExifInterface ORIENTATION_UNDEFINED.

Click Source Link

Usage

From source file:Main.java

private static Bitmap decodeExifBitmap(File file, Bitmap src) {
    try {// ww w. j  a v  a 2  s  .  co  m
        // Try to load the bitmap as a bitmap file
        ExifInterface exif = new ExifInterface(file.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        if (orientation == ExifInterface.ORIENTATION_UNDEFINED
                || orientation == ExifInterface.ORIENTATION_NORMAL) {
            return src;
        }
        Matrix matrix = new Matrix();
        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            matrix.postRotate(90);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            matrix.postRotate(180);
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            matrix.postRotate(270);
        } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) {
            matrix.setScale(-1, 1);
            matrix.postTranslate(src.getWidth(), 0);
        } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) {
            matrix.setScale(1, -1);
            matrix.postTranslate(0, src.getHeight());
        }
        // Rotate the bitmap
        return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    } catch (IOException e) {
        // Ignore
    }
    return src;
}

From source file:com.exzogeni.dk.graphics.Bitmaps.java

@Nullable
private static Bitmap applyExif(@NonNull Bitmap bitmap, String exifFilePath) {
    final int orientation = getExifOrientation(exifFilePath);
    if (orientation == ExifInterface.ORIENTATION_NORMAL || orientation == ExifInterface.ORIENTATION_UNDEFINED) {
        return bitmap;
    }//  w w  w . ja v a2  s .c  o  m
    try {
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
                getExifMatrix(orientation), true);
    } finally {
        bitmap.recycle();
    }
}

From source file:com.exzogeni.dk.graphics.Bitmaps.java

private static int getExifOrientation(String filePath) {
    try {//from  w ww .  ja va  2 s.  c om
        return new ExifInterface(filePath).getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
    } catch (IOException e) {
        Logger.error(e);
    }
    return ExifInterface.ORIENTATION_UNDEFINED;
}

From source file:com.pdftron.pdf.utils.ViewerUtils.java

public static Map readImageIntent(Intent data, Context context, Uri outputFileUri)
        throws FileNotFoundException, Exception {
    final boolean isCamera;
    if (data == null || data.getData() == null) {
        isCamera = true;// ww w .  j  a va2  s .c o  m
    } else {
        final String action = data.getAction();
        if (action == null) {
            isCamera = false;
        } else {
            isCamera = action.equals(MediaStore.ACTION_IMAGE_CAPTURE);
        }
    }

    Uri imageUri;
    if (isCamera) {
        imageUri = outputFileUri;
        AnalyticsHandlerAdapter.getInstance().sendEvent(AnalyticsHandlerAdapter.CATEGORY_FILEBROWSER,
                "Create new document from camera selected");
    } else {
        imageUri = data.getData();
        AnalyticsHandlerAdapter.getInstance().sendEvent(AnalyticsHandlerAdapter.CATEGORY_FILEBROWSER,
                "Create new document from local image file selected");
    }

    String filePath;
    if (isCamera) {
        filePath = imageUri.getPath();
    } else {
        filePath = Utils.getRealPathFromImageURI(context, imageUri);
        if (Utils.isNullOrEmpty(filePath)) {
            filePath = imageUri.getPath();
        }
    }

    // try to get bitmap
    Bitmap bitmap = Utils.getBitmapFromImageUri(context, imageUri, filePath);

    // if a file is selected, check if it is an image file
    if (!isCamera) {
        // if type is null
        if (context.getContentResolver().getType(imageUri) == null) {
            String extension = MimeTypeMap.getFileExtensionFromUrl(imageUri.getPath());
            final String[] extensions = { "jpeg", "jpg", "tiff", "tif", "gif", "png", "bmp" };

            // if file extension is not an image extension
            if (!Arrays.asList(extensions).contains(extension) && extension != null && !extension.equals("")) {
                throw new FileNotFoundException("file extension is not an image extension");
            }
            // if type is not an image
        } else if (!context.getContentResolver().getType(imageUri).startsWith("image/")) {
            throw new FileNotFoundException("type is not an image");
        }
    }

    //////////////////  Determine if image needs to be rotated   ///////////////////
    File imageFile = new File(imageUri.getPath());
    ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

    int imageRotation = 0;
    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_270:
        imageRotation = 270;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        imageRotation = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        imageRotation = 90;
        break;
    }

    // in some devices (mainly Samsung), the EXIF is not saved with the image so look at the content
    // resolver as a second source of the image's rotation
    if (imageRotation == 0) {
        String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
        Cursor cur = context.getContentResolver().query(imageUri, orientationColumn, null, null, null);
        orientation = -1;
        if (cur != null && cur.moveToFirst()) {
            orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
        }

        if (orientation > 0) {
            imageRotation = orientation;
        }
    }

    if (imageRotation != 0) {
        Matrix matrix = new Matrix();
        matrix.postRotate(imageRotation);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }

    Map<String, Object> output = new HashMap<>();
    output.put("bitmap", bitmap);
    output.put("uri", imageUri);
    output.put("path", filePath);
    output.put("camera", isCamera);
    return output;
}

From source file:im.vector.activity.ImageWebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_web_view);

    mWebView = (WebView) findViewById(R.id.image_webview);

    final Intent intent = getIntent();
    if (intent == null) {
        Log.e(LOG_TAG, "Need an intent to view.");
        finish();//from w  w w. j  a  va  2  s . co  m
        return;
    }

    mHighResUri = intent.getStringExtra(KEY_HIGHRES_IMAGE_URI);
    final int rotationAngle = mRotationAngle = intent.getIntExtra(KEY_IMAGE_ROTATION, 0);
    mOrientation = intent.getIntExtra(KEY_IMAGE_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
    mHighResMimeType = intent.getStringExtra(KEY_HIGHRES_MIME_TYPE);

    if (mHighResUri == null) {
        Log.e(LOG_TAG, "No Image URI");
        finish();
        return;
    }

    final int thumbnailWidth = intent.getIntExtra(KEY_THUMBNAIL_WIDTH, 0);
    final int thumbnailHeight = intent.getIntExtra(KEY_THUMBNAIL_HEIGHT, 0);

    if ((thumbnailWidth <= 0) || (thumbnailHeight <= 0)) {
        Log.e(LOG_TAG, "Invalid thumbnail size");
        finish();
        return;
    }

    final MXMediasCache mediasCache = Matrix.getInstance(this).getMediasCache();
    File mediaFile = mediasCache.mediaCacheFile(mHighResUri, mHighResMimeType);

    // is the high picture already downloaded ?
    if (null != mediaFile) {
        mThumbnailUri = mHighResUri = "file://" + mediaFile.getPath();
    }

    String css = computeCss(mThumbnailUri, thumbnailWidth, thumbnailHeight, rotationAngle);
    final String viewportContent = "width=640";

    final PieFractionView pieFractionView = (PieFractionView) findViewById(R.id.download_zoomed_image_piechart);

    // is the high picture already downloaded ?
    if (null != mediaFile) {
        pieFractionView.setVisibility(View.GONE);
    } else {
        mThumbnailUri = null;

        // try to retrieve the thumbnail
        mediaFile = mediasCache.mediaCacheFile(mHighResUri, thumbnailWidth, thumbnailHeight, null);
        if (null == mediaFile) {
            Log.e(LOG_TAG, "No Image thumbnail");
            finish();
            return;
        }

        final String loadingUri = mHighResUri;
        mThumbnailUri = mHighResUri = "file://" + mediaFile.getPath();

        final String downloadId = mediasCache.loadBitmap(this, loadingUri, mRotationAngle, mOrientation,
                mHighResMimeType);

        if (null != downloadId) {
            pieFractionView.setFraction(mediasCache.progressValueForDownloadId(downloadId));

            mediasCache.addDownloadListener(downloadId, new MXMediasCache.DownloadCallback() {
                @Override
                public void onDownloadProgress(String aDownloadId, int percentageProgress) {
                    if (aDownloadId.equals(downloadId)) {
                        pieFractionView.setFraction(percentageProgress);
                    }
                }

                @Override
                public void onDownloadComplete(String aDownloadId) {
                    if (aDownloadId.equals(downloadId)) {
                        pieFractionView.setVisibility(View.GONE);

                        final File mediaFile = mediasCache.mediaCacheFile(loadingUri, mHighResMimeType);

                        if (null != mediaFile) {
                            Uri uri = Uri.fromFile(mediaFile);
                            mHighResUri = uri.toString();

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Uri mediaUri = Uri.parse(mHighResUri);

                                    // save in the gallery
                                    CommonActivityUtils.saveImageIntoGallery(ImageWebViewActivity.this,
                                            mediaFile);

                                    // refresh the UI
                                    loadImage(mediaUri, viewportContent, computeCss(mHighResUri, thumbnailWidth,
                                            thumbnailHeight, rotationAngle));
                                }
                            });
                        }
                    }
                }
            });
        }
    }

    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.getSettings().setBuiltInZoomControls(true);

    loadImage(Uri.parse(mHighResUri), viewportContent, css);

    mWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            final String highResMediaURI = intent.getStringExtra(KEY_HIGHRES_IMAGE_URI);
            final MXMediasCache mediasCache = Matrix.getInstance(ImageWebViewActivity.this).getMediasCache();
            final File mediaFile = mediasCache.mediaCacheFile(highResMediaURI, mHighResMimeType);

            if (null != mediaFile) {
                FragmentManager fm = ImageWebViewActivity.this.getSupportFragmentManager();
                IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                        .findFragmentByTag(TAG_FRAGMENT_IMAGE_OPTIONS);

                if (fragment != null) {
                    fragment.dismissAllowingStateLoss();
                }

                final Integer[] icons = { R.drawable.ic_material_share, R.drawable.ic_material_forward };
                final Integer[] textIds = { R.string.share, R.string.forward };

                fragment = IconAndTextDialogFragment.newInstance(icons, textIds, Color.WHITE,
                        ImageWebViewActivity.this.getResources().getColor(R.color.vector_title_color));
                fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                    @Override
                    public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                        final Integer selectedVal = textIds[position];

                        ImageWebViewActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Intent sendIntent = new Intent(Intent.ACTION_SEND);

                                sendIntent.setType(mHighResMimeType);

                                try {
                                    sendIntent.putExtra(Intent.EXTRA_STREAM,
                                            ConsoleContentProvider.absolutePathToUri(ImageWebViewActivity.this,
                                                    mediaFile.getAbsolutePath()));
                                } catch (Exception e) {
                                }

                                if (selectedVal == R.string.forward) {
                                    CommonActivityUtils.sendFilesTo(ImageWebViewActivity.this, sendIntent);
                                } else {
                                    startActivity(sendIntent);
                                }
                            }
                        });
                    }
                });

                fragment.show(fm, TAG_FRAGMENT_IMAGE_OPTIONS);

                return true;
            }

            return false;
        }
    });

}

From source file:org.matrix.console.activity.ImageWebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        CommonActivityUtils.restartApp(this);
    }//w ww  .  j av  a  2 s.co m

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_web_view);

    mWebView = (WebView) findViewById(R.id.image_webview);

    final Intent intent = getIntent();
    if (intent == null) {
        Log.e(LOG_TAG, "Need an intent to view.");
        finish();
        return;
    }

    mHighResUri = intent.getStringExtra(KEY_HIGHRES_IMAGE_URI);
    final int rotationAngle = mRotationAngle = intent.getIntExtra(KEY_IMAGE_ROTATION, 0);
    mOrientation = intent.getIntExtra(KEY_IMAGE_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
    mHighResMimeType = intent.getStringExtra(KEY_HIGHRES_MIME_TYPE);

    if (mHighResUri == null) {
        Log.e(LOG_TAG, "No Image URI");
        finish();
        return;
    }

    MXSession session = getSession(intent);
    HomeserverConnectionConfig hsConfig = session != null ? session.getHomeserverConfig() : null;

    final int thumbnailWidth = intent.getIntExtra(KEY_THUMBNAIL_WIDTH, 0);
    final int thumbnailHeight = intent.getIntExtra(KEY_THUMBNAIL_HEIGHT, 0);

    if ((thumbnailWidth <= 0) || (thumbnailHeight <= 0)) {
        Log.e(LOG_TAG, "Invalid thumbnail size");
        finish();
        return;
    }

    final MXMediasCache mediasCache = Matrix.getInstance(this).getMediasCache();
    File mediaFile = mediasCache.mediaCacheFile(mHighResUri, mHighResMimeType);

    // is the high picture already downloaded ?
    if (null != mediaFile) {
        mThumbnailUri = mHighResUri = "file://" + mediaFile.getPath();
    }

    String css = computeCss(mThumbnailUri, thumbnailWidth, thumbnailHeight, rotationAngle);
    final String viewportContent = "width=640";

    final PieFractionView pieFractionView = (PieFractionView) findViewById(R.id.download_zoomed_image_piechart);

    // is the high picture already downloaded ?
    if (null != mediaFile) {
        pieFractionView.setVisibility(View.GONE);
    } else {
        mThumbnailUri = null;

        // try to retrieve the thumbnail
        mediaFile = mediasCache.mediaCacheFile(mHighResUri, thumbnailWidth, thumbnailHeight, null);
        if (null == mediaFile) {
            Log.e(LOG_TAG, "No Image thumbnail");
            finish();
            return;
        }

        final String loadingUri = mHighResUri;
        mThumbnailUri = mHighResUri = "file://" + mediaFile.getPath();

        final String downloadId = mediasCache.loadBitmap(this, hsConfig, loadingUri, mRotationAngle,
                mOrientation, mHighResMimeType);

        if (null != downloadId) {
            pieFractionView.setFraction(mediasCache.progressValueForDownloadId(downloadId));

            mediasCache.addDownloadListener(downloadId, new MXMediasCache.DownloadCallback() {
                @Override
                public void onDownloadStart(String aDownloadId) {
                }

                @Override
                public void onDownloadProgress(String aDownloadId, int percentageProgress) {
                    if (aDownloadId.equals(downloadId)) {
                        pieFractionView.setFraction(percentageProgress);
                    }
                }

                @Override
                public void onDownloadComplete(String aDownloadId) {
                    if (aDownloadId.equals(downloadId)) {
                        pieFractionView.setVisibility(View.GONE);

                        final File mediaFile = mediasCache.mediaCacheFile(loadingUri, mHighResMimeType);

                        if (null != mediaFile) {
                            Uri uri = Uri.fromFile(mediaFile);
                            mHighResUri = uri.toString();

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Uri mediaUri = Uri.parse(mHighResUri);

                                    // save in the gallery
                                    CommonActivityUtils.saveImageIntoGallery(ImageWebViewActivity.this,
                                            mediaFile);

                                    // refresh the UI
                                    loadImage(mediaUri, viewportContent, computeCss(mHighResUri, thumbnailWidth,
                                            thumbnailHeight, rotationAngle));
                                }
                            });
                        }
                    }
                }
            });
        }
    }

    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.getSettings().setBuiltInZoomControls(true);

    loadImage(Uri.parse(mHighResUri), viewportContent, css);

    mWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            final String highResMediaURI = intent.getStringExtra(KEY_HIGHRES_IMAGE_URI);
            final MXMediasCache mediasCache = Matrix.getInstance(ImageWebViewActivity.this).getMediasCache();
            final File mediaFile = mediasCache.mediaCacheFile(highResMediaURI, mHighResMimeType);

            if (null != mediaFile) {
                FragmentManager fm = ImageWebViewActivity.this.getSupportFragmentManager();
                IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                        .findFragmentByTag(TAG_FRAGMENT_IMAGE_OPTIONS);

                if (fragment != null) {
                    fragment.dismissAllowingStateLoss();
                }

                final Integer[] icons = { R.drawable.ic_material_share, R.drawable.ic_material_forward };
                final Integer[] textIds = { R.string.share, R.string.forward };

                fragment = IconAndTextDialogFragment.newInstance(icons, textIds, Color.WHITE, null);
                fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                    @Override
                    public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                        final Integer selectedVal = textIds[position];

                        ImageWebViewActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Intent sendIntent = new Intent(Intent.ACTION_SEND);

                                sendIntent.setType(mHighResMimeType);

                                try {
                                    sendIntent.putExtra(Intent.EXTRA_STREAM,
                                            ConsoleContentProvider.absolutePathToUri(ImageWebViewActivity.this,
                                                    mediaFile.getAbsolutePath()));
                                } catch (Exception e) {
                                }

                                if (selectedVal == R.string.forward) {
                                    CommonActivityUtils.sendFilesTo(ImageWebViewActivity.this, sendIntent);
                                } else {
                                    startActivity(sendIntent);
                                }
                            }
                        });
                    }
                });

                fragment.show(fm, TAG_FRAGMENT_IMAGE_OPTIONS);

                return true;
            }

            return false;
        }
    });

}

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  av  a 2 s  .c  o m
@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.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;// ww  w  . j  av  a2 s  . c  om
    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.google.android.gms.samples.vision.face.photo.PhotoViewerActivity.java

public Bitmap grabImage() {
    this.getContentResolver().notifyChange(photoURI, null);
    ContentResolver cr = this.getContentResolver();
    Bitmap bitmap;//from w ww .j  a v a2  s  .  com
    try {
        bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, photoURI);

        ExifInterface ei = new ExifInterface(mCurrentPhotoPath);
        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;

        case ExifInterface.ORIENTATION_NORMAL:

        default:
            break;
        }
        return bitmap;
    } catch (Exception e) {
        Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "Failed to load", e);
        return null;
    }
}

From source file:me.tipi.kiosk.ui.fragments.OCRFragment.java

@Override
public void onMetadataAvailable(Metadata metadata) {
    // This method will be called when metadata becomes available during recognition process.
    // Here, for every metadata type that is allowed through metadata settings,
    // desired actions can be performed.
    // detection metadata contains detection locations
    if (metadata instanceof DetectionMetadata) {
        // detection location is written inside DetectorResult
        DetectorResult detectorResult = ((DetectionMetadata) metadata).getDetectionResult();
        // DetectorResult can be null - this means that detection has failed
        if (detectorResult == null) {
            if (mQvManager != null) {
                // begin quadrilateral animation to its default position
                // (internally displays FAIL status)
                mQvManager.animateQuadToDefaultPosition();
            }/*from   w  w  w  .jav  a  2s .co  m*/
            // when points of interested have been detected (e.g. QR code), this will be returned as PointsDetectorResult
        } else if (detectorResult instanceof QuadDetectorResult) {
            // begin quadrilateral animation to detected quadrilateral
            mQvManager.animateQuadToDetectionPosition((QuadDetectorResult) detectorResult);
        }
    } else if (metadata instanceof ImageMetadata) {
        // obtain image
        // Please note that Image's internal buffers are valid only
        // until this method ends. If you want to save image for later,
        // obtained a cloned image with image.clone().

        if (guest.passportPath == null || TextUtils.isEmpty(guest.passportPath) || this.results == null) {
            Image image = ((ImageMetadata) metadata).getImage();

            if (image != null && image.getImageType() == ImageType.SUCCESSFUL_SCAN) {
                Timber.w("Metadata type is successful frame image, we go to save it");
                image.clone();
                Timber.w("Ocr meta data captured");
                final Bitmap bitmap = image.convertToBitmap();
                Timber.w("Metadata converted to bitmap");
                final Uri photoUri = ImageUtility.savePassportPicture(getActivity(), bitmap);
                Timber.w("OCR Uri got back from file helper with path: %s",
                        photoUri != null ? photoUri.getPath() : "NO OCR FILE PATH!!!!!");
                ExifInterface ei = null;
                try {
                    ei = new ExifInterface(photoUri.getPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }

                int orientation = ei != null
                        ? ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
                        : 0;
                Timber.w("Ocr image orientation angle is: %d", orientation);

                Bitmap rotated = null;

                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotated = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotated = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotated = rotateImage(bitmap, 270);
                    break;
                case ExifInterface.ORIENTATION_UNDEFINED:
                    rotated = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_NORMAL:
                default:
                    break;
                }

                final Uri rotatedUri = ImageUtility.savePassportPicture(getActivity(), rotated);
                Timber.w("OCR ROTATED Uri got back from file helper with path: %s",
                        rotatedUri != null ? rotatedUri.getPath() : "NO OCR FILE PATH!!!!!");
                guest.passportPath = rotatedUri.getPath();
                Timber.w("Ocr path saved with path: %s", rotatedUri.getPath());
            }
        } else {
            Timber.w("We have ocr path and it's : %s", guest.passportPath);
        }
        // to convert the image to Bitmap, call image.convertToBitmap()

        // after this line, image gets disposed. If you want to save it
        // for later, you need to clone it with image.clone()
    }
}