title: Drawable from imageview to byte array (database)
body: <p>I've been trying to fix my problem looking for questions like this one (<a href="https://stackoverflow.com/questions/4435806/drawable-to-byte">Drawable to byte[]</a>) but I couldn't fix it.</p>
  
  <p>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.</p>
  
  <p>My code:</p>
  
  <pre><code>//imageview1.setImageResource(R.drawable.pictureJM);
  imageview1.setImageDrawable(getResources().getDrawable(R.drawable.pictureJM));
  
  Drawable d1=imageview1.getDrawable();
  Bitmap bitmap =((BitmapDrawable)d1).getBitmap();  &lt;-- (The application stops here)
  
  ByteArrayOutputStream streamJM = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, streamJM);
  byte[] imageInByte = streamJM.toByteArray();
  </code></pre>
  
  <p>Can you tell me what's wrong ?</p>