1. 程式人生 > >android繪製背景平鋪Bitmap圖片

android繪製背景平鋪Bitmap圖片

public Bitmap createReBitmap(int mWidth,int mHeight,Bitmap BG) {
		int countX = (mWidth + BG.getWidth() - 1) / BG.getWidth();
		int countY = (mHeight + BG.getHeight() - 1) / BG.getHeight();
		
		Bitmap mBitmap= Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
		Canvas canvas = new Canvas(mBitmap);
		for(int idy = 0; idy < countY; ++ idy){
			for(int idx = 0; idx < countX; ++ idx){
				canvas.drawBitmap(BG, idx * BG.getWidth(), idy * BG.getHeight(), null);
			}
		}
		return mBitmap;
	}