Created
May 11, 2015 14:17
-
-
Save rafaeltoledo/4f4457ae096ebf021368 to your computer and use it in GitHub Desktop.
Convert Image to Base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String encodeBase64(String path) { | |
try { | |
File file = new File(path); | |
FileInputStream imageInFile = new FileInputStream(file); | |
byte imageData[] = new byte[(int) file.length()]; | |
imageInFile.read(imageData); | |
imageInFile.close(); | |
return Base64.encodeToString(imageData, Base64.DEFAULT); | |
} catch (Exception e) { | |
Log.e("Base64", "Failed to convert image to Base64", e); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment