@ Override public Result decode ( BinaryBitmap image , Map < DecodeHintType , ? > hints ) throws NotFoundException , FormatException { try { return doDecode ( image , hints ) ; } catch ( NotFoundException nfe ) { boolean tryHarder = hints != null && hints . containsKey ( DecodeHintType . TRY_HARDER ) ; if ( tryHarder && image . isRotateSupported ( ) ) { BinaryBitmap rotatedImage = image . rotateCounterClockwise ( ) ; Result result = doDecode ( rotatedImage , hints ) ; // Record that we found it rotated 90 degrees CCW / 270 degrees CW Map < ResultMetadataType , ? > metadata = result . getResultMetadata ( ) ; int orientation = 270 ; if ( metadata != null && metadata . containsKey ( ResultMetadataType . ORIENTATION ) ) { // But if we found it reversed in doDecode(), add in that result here: orientation = ( orientation + ( Integer ) metadata . get ( ResultMetadataType . ORIENTATION ) ) % 360 ; } result . putMetadata ( ResultMetadataType . ORIENTATION , orientation ) ; // Update result points ResultPoint [ ] points = result . getResultPoints ( ) ; if ( points != null ) { int height = rotatedImage . getHeight ( ) ; for ( int i = 0 ; i < points . length ; i ++ ) { points [ i ] = new ResultPoint ( height - points [ i ] . getY ( ) - 1 , points [ i ] . getX ( ) ) ; } } return result ; } else { throw nfe ; } } }
Note that we don t try rotation without the try harder flag even if rotation was supported .