I've been trying to fix my problem looking for questions like this one (Drawable to byte[]) but I couldn't fix it.
I'm setting a drawable picture (the user can change it too) from an imageview and later i'm trying to get this picture and convert it into a byte array to save it in a database.
My code:
//imageview1.setImageResource(R.drawable.pictureJM);
imageview1.setImageDrawable(getResources().getDrawable(R.drawable.pictureJM));
Drawable d1=imageview1.getDrawable();
Bitmap bitmap =((BitmapDrawable)d1).getBitmap(); <-- (The application stops here)
ByteArrayOutputStream streamJM = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, streamJM);
byte[] imageInByte = streamJM.toByteArray();
Can you tell me what's wrong ?