@ WorkerThread @ Nullable public String createThumbnailForImage ( String imagePath ) { if ( TextUtils . isEmpty ( imagePath ) ) return null ; File inFile = new File ( imagePath ) ; if ( ! inFile . exists ( ) ) return null ; File thumbnailFile = randomPath ( imagePath ) ; if ( thumbnailFile . exists ( ) ) return thumbnailFile . getAbsolutePath ( ) ; Bitmap inBitmap = readImageFromPath ( imagePath , THUMBNAIL_SIZE , THUMBNAIL_SIZE ) ; if ( inBitmap == null ) return null ; ByteArrayOutputStream compressStream = new ByteArrayOutputStream ( ) ; inBitmap . compress ( Bitmap . CompressFormat . JPEG , THUMBNAIL_QUALITY , compressStream ) ; try { compressStream . close ( ) ; thumbnailFile . createNewFile ( ) ; FileOutputStream writeStream = new FileOutputStream ( thumbnailFile ) ; writeStream . write ( compressStream . toByteArray ( ) ) ; writeStream . flush ( ) ; writeStream . close ( ) ; return thumbnailFile . getAbsolutePath ( ) ; } catch ( Exception ignored ) { return null ; } }
Create a thumbnail for the image .