---- bitmap和canvas画出叠加的2张照片
--- 图片1原图
------ 图片2原图
--------- 代码实现
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
int outWidth = options.outWidth;
int outHeight = options.outHeight;
Bitmap background2 = BitmapFactory.decodeResource(getResources(), R.drawable.icon, null);
Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.sophie, null);
// 创建一个新的和SRC长度宽度一样的位图
Bitmap newbmp = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
//draw bg into
cv.drawBitmap(background2, 0, 0, null);
// 在 0,0坐标开始画入bg
// draw fg into
cv.drawBitmap(foreground, 30, 60, null);
imageViewBlur2.setImageBitmap(newbmp);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
int outWidth = options.outWidth;
int outHeight = options.outHeight;
Bitmap background2 = BitmapFactory.decodeResource(getResources(), R.drawable.icon, null);
Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.sophie, null);
// 创建一个新的和SRC长度宽度一样的位图
Bitmap newbmp = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
//draw bg into
cv.drawBitmap(background2, 0, 0, null);
// 在 0,0坐标开始画入bg
// draw fg into
cv.drawBitmap(foreground, 10, 30, null);
cv.drawBitmap(foreground, 20, 50, null);
cv.drawBitmap(foreground, 30, 70, null);
cv.drawBitmap(foreground, 40, 90, null);
imageViewBlur2.setImageBitmap(newbmp);
----- 如果想在图片上加一层灰色遮罩,canvas实现 图层的叠加,灰色遮罩是bitmap
实现思路,在图片上再画一层0x33000000颜色的bitmap
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
int outWidth = options.outWidth;
int outHeight = options.outHeight;
Bitmap foreground = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
foreground.eraseColor(0x4d000000);//填充颜色
Bitmap background2 = BitmapFactory.decodeResource(getResources(), R.drawable.icon, null);
// Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.sophie, null);
// 创建一个新的和SRC长度宽度一样的位图
Bitmap newbmp = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
//draw bg into
cv.drawBitmap(background2, 0, 0, null);
//画前景
cv.drawBitmap(foreground, 0, 0, null);
imageViewBlur2.setImageBitmap(newbmp);
eraseColor
void eraseColor (int c)
Fills the bitmap's pixels with the specified Color.
Bitmap foreground = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888);
foreground.eraseColor(0x4d000000);//填充颜色