private String getBase64String() {
// give your image file url in mCurrentPhotoPath
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// In case you want to compress your image, here it's at 40%
// here i use JPEG image but now can anyone tell how can i convert any format image in String
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
答案 0 :(得分:0)
您可以使用Base64 Android类:
@Value("#{mysql.databaseName}")
private String databaseName;
不过,您必须将图像转换为字节数组。
String ecodImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);