0
我在應用程序中工作,我希望用戶選擇多個並將它們轉換爲base64,以便我可以將它發送到服務器。它是不可能性,以從圖庫中選擇多張圖像,然後將它們轉換爲Base64,然後將其發送到服務器如何選擇多個圖像並將其轉換爲基本64?
Intent intent = new Intent();
intent.setType("*/*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "android.intent.action.SEND_MULTIPLE"), SELECT_PICTURE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == SELECT_PICTURE) {
if (resultCode == RESULT_OK) {
//data.getParcelableArrayExtra(name);
//If Single image selected then it will fetch from Gallery
filePath = data.getData();
filePath = data.getData();
if (null != filePath) {
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), filePath);
// img.setImageBitmap(bitmap);
if (filePath.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(filePath, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
file_name = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
// text.setText(file_name+",");
img_name.add(file_name);
img_pic.add(getStringImage(bitmap));
// Toast.makeText(this, "1." + file_name, Toast.LENGTH_SHORT).show();
}
} finally {
cursor.close();
}
} else {
String path = data.getData().getPath();
file_name = path.substring(path.lastIndexOf("/") + 1);
// text.setText(file_name);
img_name.add(file_name);
img_pic.add(getStringImage(bitmap));
//Toast.makeText(this, "2." + file_name, Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
}
的可能的複製(https://stackoverflow.com/questions/4830711 /如何對轉換-A-圖像 - 到 - 基於64位字符串) –