我有一个无缝背景,我已经使用下面的代码重复地在屏幕上显示它:
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
bitmapDrawable.setTileModeY(Shader.TileMode.REPEAT);
mBackground.setBackground(bitmapDrawable);
但是,我遇到了稍后保存位图的问题。背景是宽度和高度匹配的屏幕尺寸。当我尝试使用下面的代码来获取位图时,保存的图像就是原始的无缝模式。
((BitmapDrawable) mBackground.getBackground()).getBitmap()
我不知道如何生成重复的背景图像。
答案 0 :(得分:3)
此代码可能有所帮助:
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