0
private Bitmap getBitmapScaled(String dirname, String filename) {
    Bitmap compressedImage = null;
    Bitmap compressedImage1 = null;
    try {
        Matrix matrix = new Matrix();
        File file = getMeterFilePath(dirname, filename);

        ExifInterface exif = new ExifInterface(
                file.getAbsolutePath());
        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        Log.d("1111111111111",""+orientation);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                matrix.postRotate(270);
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                matrix.postRotate(180);

                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                matrix.postRotate(0);
                break;

            case ExifInterface.ORIENTATION_UNDEFINED:
                matrix.postRotate(90);

                break;
        }
        compressedImage = new Compressor.Builder(mContext)
                .setMaxWidth(AppConstants.IMAGE_WIDTH)
                .setMaxHeight(AppConstants.IMAGE_HEIGHT)
                .setQuality(1)
                .setCompressFormat(Bitmap.CompressFormat.JPEG)
                .build()
                .compressToBitmap(file);

        compressedImage1 = Bitmap.createBitmap(compressedImage, 0, 0, compressedImage.getWidth(),
                compressedImage.getHeight(), matrix, true);
        if (compressedImage1 != null)
            compressedImage1 = CommonUtils.addWaterMarkDate(compressedImage1, CommonUtils.getCurrentDateTime());
    } catch (Exception e) {
    }

    return compressedImage1;
}

I have been using this code to create bitmap. Using this, the height of the is image is not being compressed. The second compression is used to rotate the image, I feel that there is something wrong with the second function. Earlier I used only the first function to create bitmap which used to work fine, but not with rotating the image, the second function is not working properly.

0 Answers0