1
I am creating an application that I register a search image from the mobile gallery, saving it in SQLITE, and searching later to show in a view Recycler, however, debugging realized that the bitmap object is getting null.
Obs1: the information is being saved as SQLITE BLOB object,
Obs2: I’m manipulating the image as byte[]
follows some code
INSERTION IN SQLITE:
pacote.img = imageViewToByte(imag_pacote);
public static byte[] imageViewToByte(ImageView image) {
Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
pacoteRepositorio.inserir(pacote);
public void inserir(Pacote pacote){
ContentValues contentValues = new ContentValues();
contentValues.put("nome", pacote.nome);
contentValues.put("img", String.valueOf(pacote.img));
conexao.insertOrThrow("PACOTE",null, contentValues);
}
Theoretically it’s working properly !!!!
SEARCH CODE *HERE I BELIEVE IS THE ERROR
Public list of searchPacksPendentes() throws Parseexception { List packages = new Arraylist();
StringBuilder sql = new StringBuilder();
sql.append(" SELECT * ");
sql.append(" FROM PACOTE");
sql.append(" WHERE pendente = 1");
Cursor resultado = conexao.rawQuery(sql.toString(), null);
if(resultado.getCount() > 0){
resultado.moveToFirst();
do{
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
Pacote pac = new Pacote();
pac.id = resultado.getInt(resultado.getColumnIndexOrThrow("id"));
pac.nome = resultado.getString(resultado.getColumnIndexOrThrow("nome"));
pac.img = resultado.getBlob(resultado.getColumnIndexOrThrow("img"));
pacotes.add(pac);
}while(resultado.moveToNext());
}
return pacotes;
}
byte[] imagen = pacote.img;
Bitmap bitmap = BitmapFactory.decodeByteArray(imagen,0, imagen.length); //<< RETORNANDO NULL
holder.img_pacote.setImageBitmap(bitmap);
Here it shows that BYTE[] is arriving normally, however when I put in Bitmap GETS null
obs3: I saw that the object (byte[]imagen) is receiving an array normally, with 11 positions