Triangle shaped ImageView with drag, scroll amp; zoom onTouch Android(具有拖动、滚动和功能的三角形 ImageViewzoom onTouch Android)
问题描述
我在一个ImageView
中添加了三个不同的bitmap
,如下图所示.但问题是在 Bitmap
设置为 ImageView
后我无法对其进行编辑.我想拖动、滚动和在 ImageView
中缩放单个 Bitmap
.
I've added three different bitmap
to one ImageView
as shown in picture below. But the problem is that I cannot edit it after the Bitmap
is set to ImageView
.
I want to drag, scroll & zoom the individual Bitmap
in the ImageView
.
我获取组合 bitmap
的代码是:
My code for getting the combined bitmap
is:
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;
}
感谢任何帮助.
推荐答案
这里是如何屏蔽图像的源示例的链接
here is a link for source example of how to mask image
https://github.com/hotveryspicy/MaskImage
来自这个问题的参考
在帧中屏蔽(裁剪)图像
编辑
对于单独的放大和缩小,您希望这三个位图具有不同的布局(您需要制作自定义图像视图),因此请尝试下面描述如何制作您自己的自定义布局(三角形图像视图)等的 URL.
for individual zoom in and zoom out you want these three bitmaps in different layout (you need to make custom image view ) so try below URL that describe how to make your own custom layout (image view in triangle shape) etc.
https://github.com/thecodepath/android_guides/wiki/Defining-自定义视图
这篇关于具有拖动、滚动和功能的三角形 ImageViewzoom onTouch Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有拖动、滚动和功能的三角形 ImageViewzoom onTouch Android
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01