1

Currently I am working on a project with Particle which works fine with colour constants, but I want to use drawable/bitmap instead.

DATA = new int[]{16777215, -2130706433, 16777215};

and than passing onto create bitmap with DATA.

BMP = Bitmap.createBitmap(DATA, 0, 5, 1, 1, Bitmap.Config.ARGB_8888);

How should I use drawable resource and pass it on to create bitmap?

I have already tried context.getResources() and also have tried with a class

public class App extends Application {
    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
    }

    public static Context getContext() {
        return mContext;
    }
}

And use App.getContext().getResources(), but it's not working. I am trying to create Bitmap in abstract static class.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
TanKav
  • 11
  • 3
  • 1
    Possible duplicate of [How to convert a Drawable to a Bitmap?](http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap) – Kunu Jan 02 '16 at 06:53

1 Answers1

1

Use the bitmap factory method to decode the drawable resource like

Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.your_resource);
insomniac
  • 11,146
  • 6
  • 44
  • 55