Android: BitmapDrawable.Draw (Canvas) Doesn't seem to work

I'm trying to focus a 20x20 background on my user view, but for some reason I can't either.

BitmapDrawable background; background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.back)); background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); background.draw(canvas); 

Does anyone have an idea why it is not working?

+8
android bitmap draw
source share
3 answers

You can use BitmapDrawable, but first you have to set boundaries so that it knows how much needs to be done:

 BitmapDrawable background; background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(),R.drawable.back)); //in this case, you want to tile the entire view background.setBounds(0, 0, myView.getWidth(), myView.getHeight()); background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); background.draw(canvas); 
+13
source share

You are probably getting warnings in your log regarding SKImageDecoder crashing. If you create a resource through xml, you need to restore it through (BitmapDrawable) getResources().getdrawable(id)

0
source share

You have it in the opposite direction. Instead of passing the View canvas to the bitmap draw method, draw a bitmap on the View canvas using Canvas.drawBitmap

-one
source share

All Articles