/** * Write the given {@link Bitmap} to {@code imageFile}, in {@link CompressFormat#JPEG} format */ public boolean writeImageToFileJpeg(File imageFile, Bitmap image) { return writeImageToFile(imageFile, image, Bitmap.CompressFormat.JPEG, 95); }
/** * Share the given bitmap with given format * * @param bitmap Image * @param format A {@link Bitmap.CompressFormat}, supporting JPEG,PNG,WEBP * @param imageName Filename without extension * @param quality Quality of the exported image [0-100] * @return if success, true */ public boolean shareImage(Bitmap bitmap, Bitmap.CompressFormat format, int quality, String imageName) { try { String ext = format.name().toLowerCase(); File file = File.createTempFile(imageName, "." + ext.replace("jpeg", "jpg"), _context.getExternalCacheDir()); if (bitmap != null && new ContextUtils(_context).writeImageToFile(file, bitmap, format, quality)) { shareStream(file, "image/" + ext); return true; } } catch (IOException e) { e.printStackTrace(); } return false; }