Здравствуйте. Пожалуйста, проверьте код ниже
Первый метод используется для преобразования файла в = в base64, а второй метод - для сжатия любого изображения.Вы можете использовать этот код для кодирования в base64 и добавления строки параметров мыла, которая возвращается из первого метода
private String getEncodeData(String filePath) {
String encodedimage1 = null;
if (filePath != null && filePath.length() > 0) {
try {
Bitmap bm = decodeFile(new File (filePath));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 50, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
encodedimage1= Base64.encodeToString(b, Base64.DEFAULT);
} catch (Exception e) {
System.out
.println("Exception: In getEncodeData" + e.toString());
}
}
return encodedimage1;
}
private Bitmap decodeFile(File f){
Bitmap b = null;
final int IMAGE_MAX_SIZE = 100;
try {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream fis = new FileInputStream(f);
BitmapFactory.decodeStream(fis, null, o);
fis.close();
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = (int) Math.pow(2.0, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
fis = new FileInputStream(f);
b = BitmapFactory.decodeStream(fis, null, o2);
fis.close();
} catch (Exception e) {
Log.v("Exception in decodeFile() ",e.toString()+"");
}
return b;
}
Пожалуйста, дайте мне знать о любых других трудностях