Android Bitmap to Base64 String

use following method to convert bitmap to byte array: ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream .toByteArray(); to encode base64 from byte array use following method String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

How to get Bitmap from an Uri?

Here’s the correct way of doing it: protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { Uri imageUri = data.getData(); Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri); } } If you need to load very large images, the following code will load it in in tiles (avoiding large memory … Read more

Saving and Reading Bitmaps/Images from Internal memory in Android

Use the below code to save the image to internal directory. private String saveToInternalStorage(Bitmap bitmapImage){ ContextWrapper cw = new ContextWrapper(getApplicationContext()); // path to /data/data/yourapp/app_data/imageDir File directory = cw.getDir(“imageDir”, Context.MODE_PRIVATE); // Create imageDir File mypath=new File(directory,”profile.jpg”); FileOutputStream fos = null; try { fos = new FileOutputStream(mypath); // Use the compress method on the BitMap object to … Read more