我已将三个不同的bitmap
添加到一个ImageView
,如下图所示。但问题是,在Bitmap
设置为ImageView
后,我无法对其进行编辑。
我想拖动,滚动和放大缩放Bitmap
中的个人ImageView
。
获取合并bitmap
的代码是:
Bitmap setBitmapInTriangleShape(Bitmap bitmap1, Bitmap bitmap2,
Bitmap bitmap3) {
/*
* int[] values= new int[2]; mImageView.getLocationOnScreen(values);
*/
double screenHeightAspect = 2.5;
Bitmap drawnBitmap = null;
bitmap1 = Bitmap.createScaledBitmap(bitmap1, screenWidth,
(int) (screenHeight / screenHeightAspect), true);
bitmap2 = Bitmap.createScaledBitmap(bitmap2, screenWidth,
(int) (screenHeight / screenHeightAspect), true);
bitmap3 = Bitmap.createScaledBitmap(bitmap3, screenWidth,
(int) (screenHeight / screenHeightAspect), true);
try {
drawnBitmap = Bitmap
.createBitmap(screenWidth,
(int) (screenHeight / screenHeightAspect),
Config.ARGB_8888);
Canvas canvas = new Canvas(drawnBitmap);
canvas.drawColor(Color.TRANSPARENT);
// ---------------------------------------------------------------
Paint paint = new Paint();
paint.setStrokeWidth(4);
paint.setColor(getResources().getColor(
R.color.gray_divider_reg_edit_grid_1));
paint.setStyle(Paint.Style.FILL_AND_STROKE);
Path path = new Path();
BitmapShader bms = new BitmapShader(bitmap1, TileMode.CLAMP,
TileMode.CLAMP);
paint.setStyle(Style.FILL);
paint.setShader(bms);
// bms.setLocalMatrix(matrix);
// -----------------=for photo 1-----------------------------
path.reset();
path.setFillType(Path.FillType.EVEN_ODD);
path.lineTo(0, 0);
path.lineTo((int) (screenWidth * 0.80), 0);
// path.lineTo(0, 15);
path.lineTo(0, (int) (screenHeight * 0.8706 / screenHeightAspect));
path.close();
canvas.drawPath(path, paint);
Matrix mt = new Matrix();
canvas.drawBitmap(bitmap1, new Matrix(), null);
// -------------------for photo 3-----------------------------
BitmapShader bmsUo = new BitmapShader(bitmap3, TileMode.CLAMP,
TileMode.CLAMP);
paint.setStyle(Style.FILL);
paint.setShader(bmsUo);
// bms.setLocalMatrix(matrix);
path.reset();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo((int) (screenWidth * 0.80), 0);
path.lineTo((int) (screenWidth * 0.80), 0);
path.lineTo(screenWidth, 0);
path.lineTo(screenWidth, (int) (screenHeight / screenHeightAspect));
// path.lineTo(800,800);
path.lineTo((int) (screenWidth * 0.88),
(int) (screenHeight / screenHeightAspect));
path.lineTo((int) (screenWidth * 0.50),
(int) (screenHeight * 0.32 / screenHeightAspect));
path.close();
canvas.drawPath(path, paint);
// ---------------------for photo 2-------------------------
BitmapShader bmsUop = new BitmapShader(bitmap2, TileMode.CLAMP,
TileMode.CLAMP);
paint.setStyle(Style.FILL);
paint.setShader(bmsUop);
// bmsUop.setLocalMatrix(matrix);
path.reset();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo((int) (screenWidth * 0.50),
(int) (screenHeight * 0.32 / screenHeightAspect));
path.lineTo((int) (screenWidth * 0.50),
(int) (screenHeight * 0.32 / screenHeightAspect));
path.lineTo((int) (screenWidth * 0.88),
(int) (screenHeight / screenHeightAspect));
path.lineTo(0, (int) (screenHeight / screenHeightAspect));
path.lineTo(0, (int) (screenHeight / screenHeightAspect * 0.8706));
path.close();
canvas.drawPath(path, paint);
} catch (Exception e) {
e.printStackTrace();
}
return drawnBitmap;
}
感谢任何帮助。
答案 0 :(得分:1)
这是一个如何屏蔽图像的源代码的链接
https://github.com/hotveryspicy/MaskImage
引用这个问题
编辑
对于个人放大和缩小,您希望这三个位图采用不同的布局(您需要制作自定义图像视图),因此请尝试下面的URL来描述如何制作自己的自定义布局(三角形图像视图)等。< / p>
https://github.com/thecodepath/android_guides/wiki/Defining-Custom-Views