title: How to save image from drawable resource to sd card?
body: <p>So, i have a view like on the image below. Plus I will add a Save button. You can also see my XML file. I am using this code to load image from drawable folder by pressing the next and previous buttons:</p>
  
  <pre><code>public void onClick(View v) {
          switch (v.getId()){
  
          case R.id.bNext:
              a++;
              setImage(a);
              break;
          case R.id.bPrevious:
              if(a&gt;0)
              {
                  a--;
                  setImage(a);  
                  break;
              }
          }
      }
      private void setImage(int a){
          if (a == 0)
          {
          slika.setImageResource(R.drawable.l2);
          a = 1;
          }
          else if (a == 1)
          {
          slika.setImageResource(R.drawable.l3);
          a = 2;
          }
          else if (a == 2)
          {
          slika.setImageResource(R.drawable.l4);
          a = 3;
          }
          else if (a == 3)
          {
          slika.setImageResource(R.drawable.l5);
          a = 4;
          }
          else if (a == 4)
          {
          slika.setImageResource(R.drawable.l6);
          a = 5;
          }
  .
  .
  .
  .
  .
          else if (a == 55)
          {
          slika.setImageResource(R.drawable.l57);
          a = 56;
          }
          }
  </code></pre>
  
  <p>I need to save the image that is currently on the screen. I found some answers on stackoverflow, but those are all for specific image with known name. I don't know what image a user will want to save.</p>
  
  <p><img src="https://i.stack.imgur.com/s7Tcn.png" alt="enter image description here"></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="fill_parent"
          android:gravity="center"&gt;
  
                  &lt;ImageView
              android:id="@+id/imageView1"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_centerHorizontal="true"/&gt;
  
          &lt;Button
              android:id="@+id/bMenu"
              android:layout_width="80dp"
              android:layout_height="35dp"
              android:layout_alignParentBottom="true"
              android:layout_marginBottom="10dp"
              android:layout_marginLeft="120dp"
              android:background="@drawable/buttons"
              android:gravity="center"
              android:padding="0dp"
              android:text="Menu"
              android:textColor="#ffffff"
              android:textSize="23dp" /&gt;
  
          &lt;Button
              android:id="@+id/bNext"
              android:layout_width="80dp"
              android:layout_height="35dp"
              android:layout_alignParentBottom="true"
              android:layout_marginBottom="10dp"
              android:layout_marginLeft="220dp"
              android:background="@drawable/buttons"
              android:padding="0dp"
              android:text="Next"
              android:textSize="23dp"
              android:textColor="#ffffff" /&gt;
  
          &lt;Button
              android:id="@+id/bPrevious"
              android:layout_width="80dp"
              android:layout_height="35dp"
              android:layout_alignParentBottom="true"
              android:layout_marginBottom="10dp"
              android:layout_marginLeft="20dp"
              android:background="@drawable/buttons"
              android:gravity="center"
              android:padding="0dp"
              android:text="Previous"
              android:textColor="#ffffff"
              android:textSize="23dp" /&gt;
  
      &lt;/RelativeLayout&gt;
  </code></pre>