title: How to get a Bitmap from VectorDrawable
body: <p><a href="https://i.stack.imgur.com/ni4qs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ni4qs.png" alt="Pie"></a></p>
  
  <p>I'm still trying to solve the problem I've had since a couple of days ago and I still have not found a solution. However, I am getting there step by step. Now I have run into another roadblock.</p>
  
  <p>I am trying to get <code>Bitmap.getpixel(int x, int y)</code> to return the <code>Color</code> of what the user has touched using <code>OnTouchListener</code>. The pie is a <code>VectorDrawable</code> resource, <code>vectordrawable.xml</code> I don't need to do anything with the pixel data yet, I just need to test it. So I made a <code>TextView</code> that will spit out the <code>Color</code> touched.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      ImageView imageView;
      TextView textView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          imageView = (ImageView) findViewById(R.id.imageView);
          textView = (TextView) findViewById(R.id.textView);
  
          imageView.setOnTouchListener(imageViewOnTouchListener);
      }
  
      View.OnTouchListener imageViewOnTouchListener = new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent event) {
  
              Drawable drawable = ((ImageView)view).getDrawable();
              //Bitmap bitmap = BitmapFactory.decodeResource(imageView.getResources(),R.drawable.vectordrawable);
              Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
  
              int x = (int)event.getX();
              int y = (int)event.getY();
  
              int pixel = bitmap.getPixel(x,y);
  
              textView.setText("touched color: " + "#" + Integer.toHexString(pixel));
  
              return true;
          }
      };
  }
  </code></pre>
  
  <p>But my app encounters a fatal error as soon as I touch the <code>ImageView</code>,  gives the "Unfortunately,..." message and quits. In the stack trace, I found this.</p>
  
  <pre><code>java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
      at com.skwear.colorthesaurus.MainActivity$1.onTouch(MainActivity.java:38)
  </code></pre>
  
  <p>and line 38 is this one,</p>
  
  <pre><code>Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
  </code></pre>
  
  <p>I kind of followed <a href="http://android-er.blogspot.in/2012/10/get-touched-pixel-color-of-scaled.html" rel="noreferrer">this</a>. What am I doing wrong? Is it because it's a <code>VectorDrawable</code>. What can I do to get the <code>Color</code>? You can see that I have also tried <code>BitmapFactory</code> to cast the <code>Drawable</code>. Could it also be a problem with the API level of <code>VectorDrawable</code> since it was added like API 21?</p>