1

I have a seamless background, and I have successfully show it on the screen repeatedly using below code:

BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
bitmapDrawable.setTileModeY(Shader.TileMode.REPEAT);
mBackground.setBackground(bitmapDrawable);

However, I got an issue with getting the bitmap to save later. The background is matched screen size in width and height. When I try with below code to get the bitmap, the saved image is just the original seamless pattern.

((BitmapDrawable) mBackground.getBackground()).getBitmap()

I have no idea how to generate repeated background image.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ralphilius
  • 1,746
  • 2
  • 16
  • 28

1 Answers1

3

This code may help:

    int width = 100;//initialise
    int height= 100;//initialise

    //you say "The background is matched screen size in the question"
    width  = mBackground.getWidth();//  get width  of screen
    height = mBackground.getHeight();// get height of screen

    //Create bitmap for canvas        
    Bitmap tiledBitmap = Bitmap.createBitmap( width , height, Bitmap.Config.ARGB_8888 );//create a Bipmap for us to save later
    canvas = new Canvas( tiledBitmap );//associate bitmap to canvas

    bitmapDrawable.setBounds( 0, 0, width , height );//set bounds
    bitmapDrawable.draw( canvas );//draw tiled image to canvas ( and so Bitmap )

    //tiledBitmap now contains your tiled image
Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54