I am trying to save android form form sdk in sqlite database. And everything turned out fine. The image will be stored in the database as a blob. This is the crude code I used for this.
Bitmap bitmap = BitmapFactory.decodeFile(filePath); imgView.setImageBitmap(bitmap); int size = bitmap.getWidth() * bitmap.getHeight(); ByteArrayOutputStream out = new ByteArrayOutputStream(size); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace();} byte[] x = out.toByteArray();
On the database side, the code is as follows
ContentValues values = new ContentValues(); byte[] bytes = null; bytes = img_bytes.getBytes(); values.put("IMAGE", bytes);
And for display, I used the code as shown below.
ImageView image = new ImageView(this); byte[] img_bytes = result.get("IMAGE").getBytes(); Bitmap bMap = BitmapFactory.decodeByteArray(img_bytes, 0, img_bytes.length); image.setImageBitmap(bMap);
When I printed the string value of the byte array, it turned out like [B @ 44da2db0. But the byte array is not displayed in the image.
Someone please help me with this. Thanks
source share