I have a an Android resource drawable that I want to use in a BitmapShader call to a paint object.
I keep getting problems in trying to convert this android drawable to bitmap.
I have tried:
Drawable theBackground = ContextCompat.getDrawable(FullscreenActivity.wkContextRef.get(),R.drawable.grid_background);
Bitmap backDraw = ((BitmapDrawable)theBackground).getBitmap();
Then, it says that I can not convert GradientDrawable to BitmapDrawable!
I have also tried:
Bitmap bii = BitmapFactory.decodeResource(FullscreenActivity.wkContextRef.get().getResources(),R.drawable.grid_background);
Then, when I set the BitmapShader on the paint it says the Bitmap must be non-null.
This is how I define my paint object and how I set the shader on the paint object:
Paint pintura=new Paint();
pintura.setStyle(Paint.Style.FILL_AND_STROKE);
pintura.setPathEffect(new ComposePathEffect(
new CornerPathEffect(100f) , new DiscretePathEffect(15f,55f)
));
pintura.setShader(new BitmapShader(bii,
Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
How can I use this resource drawable in the BitmapShader call?
I have tried converting the resource drawable to a bitmap by using BitmapFactory.decodeResource() AND
creating a Drawable with ContextCompat.getDrawable() and then converting that drawable to BitmapDrawable to use the method getBitmap().