content: package ay3524.com.popularmovies.Utils;
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Color;
  import android.graphics.drawable.BitmapDrawable;
  import android.support.v7.graphics.Palette;
  import android.widget.ImageView;
  
  import java.io.ByteArrayOutputStream;
  
  /**
   * Created by Ashish on 29-11-2016.
   */
  
  public class BitmapUtility {
      // convert from bitmap to byte array
      public static byte[] getBytes(Bitmap bitmap) {
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
          return stream.toByteArray();
      }
  
      // convert from byte array to bitmap
      public static Bitmap getImage(byte[] image) {
          return BitmapFactory.decodeByteArray(image, 0, image.length);
      }
  
      public static int getPaletteColor(ImageView imageView) {
          BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
          Bitmap bitmap = drawable.getBitmap();
          Palette palette = Palette.generate(bitmap);
          int x = Color.parseColor("#ea0101");
          return palette.getVibrantColor(x);
      }
  }
  