如图所示,在友盟分享的时候需要图中所示的图片,但是里面的图片是四张图片拼接起来的,因为牌谱的颜色随时可能更换,所以图片是不固定的,花色也需要随时更换,上代码;
public Bitmap first() { // 防止出现Immutable bitmap passed to Canvas constructor错误 Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.chouma).copy(Bitmap.Config.ARGB_8888, true); // Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable( // R.drawable.chouma)).getBitmap(); Bitmap bitmaptest = ((BitmapDrawable) getResources().getDrawable( R.drawable.chouma)).getBitmap(); Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable( R.drawable.bh2)).getBitmap(); Bitmap bitmapfirst = rotateBitmaps(bitmap2,10); Bitmap bitmaotest = rotateBitmap(bitmaptest,0); Bitmap backmap = rotateBitmaps(bitmap1,-30); Bitmap bitmap3 = ((BitmapDrawable) getResources().getDrawable( R.drawable.fk1)).getBitmap(); Bitmap bitmsecond = rotateBitmaps(bitmap3,-20); Bitmap newBitmap = null; newBitmap = Bitmap.createBitmap(backmap); Canvas canvas = new Canvas(newBitmap); Paint paint = new Paint(); int w = backmap.getWidth(); int h = backmap.getHeight(); int w_2 = bitmapfirst.getWidth(); int h_2 = bitmapfirst.getHeight(); int w_3 = bitmsecond.getWidth(); int h_3 = bitmsecond.getHeight(); paint.setColor(Color.GRAY); paint.setAlpha(0); // Log.e("yinshi","bitmap1.getWidth()"+bitmap1.getWidth()/2+"bitmap1.getHeight()"+bitmap1.getHeight()/2); canvas.drawRect(0, 0, backmap.getWidth()/2, backmap.getHeight()/2, paint); // canvas.drawRect(0, 0, 0, 0, paint); paint = new Paint(); // Log.e("yinshi","----Math.abs(w_2 - w_3) / 4----"+Math.abs(w_2 - w_3) / 4+"-----Math.abs(h - h_3) / 4---"+Math.abs(h - h_3) / 4); canvas.drawBitmap(bitmaotest,Math.abs(w - w_2)/2, 25, paint); canvas.drawBitmap(bitmsecond, Math.abs(w_2 - w_3) /2, -7, paint); canvas.drawBitmap(bitmapfirst, Math.abs(w - w_2), -6, paint); canvas.save(Canvas.ALL_SAVE_FLAG); // 存储新合成的图片 // canvas.translate(0,600); canvas.restore(); return newBitmap; }图中的花色我暂时是写死的,练习demo,花色是可以根据服务器的数据进行更换的
拼接图中花色的旋转动画效果
public static Bitmap rotateBitmap(Bitmap bitmap, int degrees) { if (degrees == 0 || null == bitmap) { return bitmap; } Matrix matrix = new Matrix(); // Log.e("yinshi","bitmap.getWidth() / 2-----"+bitmap.getWidth() / 2+"----bitmap.getHeight() / 2---"+bitmap.getHeight() / 2); // matrix.preTranslate(1,1.5f); matrix.postRotate(degrees, bitmap.getWidth() / 3, bitmap.getHeight() / 3); // matrix.postTranslate(0,bitmap.getHeight()); // matrix.preTranslate(0,bitmap.getHeight()); matrix.setTranslate(0,200); Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // Log.e("yinshi","bitmap.getWidth()"+bitmap.getWidth()+"bitmap.getHeight()"+bitmap.getHeight()); if (null != bitmap) { bitmap.recycle(); } return bmp; }