Encode images
The first solution that occurred to me is to encode the image to a string in base64, thus writing the same in a file:
Function that receives image and returns base64
public static String encodeTobase64(Bitmap image)
{
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
Log.e("LOOK", imageEncoded);
return imageEncoded;
}
Function that receives base64 and returns the image
public static Bitmap decodeBase64(String input)
{
byte[] decodedByte = Base64.decode(input, 0);
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
}
With this solution, when you save the images, you encode them in base64 and save them to a file, for example nomeDaImagem.codedImg
.
When you need to present them, you decode the string read from the file and present the image.
User Response Credentials @RomanTruba this answer in SOEN.
Private Images
If the idea is that the files can only be accessed by the application in question, and no other can move them, the solution is to have those files in Internal Storage where they are private and accessible only by the User ID of the system that was assigned to the application when it was installed.
For this scenario it is unnecessary to encode and decode the files as they can only be accessed by the application that created them.