I have the following code created by a friend on Android using Java.
private void carregaFotos(Long idResenhaCurrent, Long idResenhaGedave) {
String root = Environment.getExternalStorageDirectory().toString();
Resources res = getResources();
File myDir = new File(root + "/" + res.getString(R.string.app_name_files_res) + "/Imagem");
ResenhaEqFoto foto = null;
List<ResenhaEquideoFotos> fotosList = new ArrayList<>();
fotosList = equideoFotosUtil.getListDados(equideoDados.getId());
int qtde = fotosList.size();
for (int i = 0; i < qtde; i++) {
foto = new ResenhaEqFoto();
String path = myDir+"/"+fotosList.get(i).getNomeArquivo().trim();
Bitmap bm = BitmapFactory.decodeFile(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 70, baos); // bm is the bitmap object era quality 100
byte[] b = baos.toByteArray();
foto.setImagem( Base64.encode(b, 0) );
// more data added to the "foto" object
...
dadosFotoList.add( foto );
}
}
The code get an image that are stored inside the app project folder, get the file and transform it into a Bitmap, after that transform it in a ByteArrayOutputStream and compress the file.
After that encode the file into Base64 String.
This is what I could understand of it.
First of all, what exactly is
byte[] b
in Swift and how can I use the code below
Base64.encode(b, 0)
with Swift?
The code above generate the following JSON, take a look in the link below:
https://jsonblob.com/a260a537-da9f-11eb-b281-0b0ddf298faa
The part that I want to achieve is the "imagem" part.
A array of ints(or bytes).
How can I achieve this result?