三角形状的ImageView与阻力,滚动和放大器;变焦onTouch的Andr​​oid放大器、变焦、阻力、形状

2023-09-06 22:57:42 作者:雅痞绅士

我添加的三种不同的位图来一个的ImageView 如上图下面。但问题是,我不能在位图后,编辑设置为的ImageView 。 我想为阻力,滚动和放大器;放大单个位图的ImageView

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.

我的code获取合并位图是:

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;

}

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

下面是一个链接,如何掩盖图像源的例子

here is a link for source example of how to mask image

https://github.com/hotveryspicy/MaskImage

这是这个问题的裁判

遮罩(裁剪)图像帧

修改

在各个放大和缩小你想这三个位图在不同的布局(你需要自定义图像视图),这样试试下面介绍如何使自己的自定义布局(以三角形图像视图)等网址

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/the$c$ CPATH / android_guides /维基/定义 - 自定义 - 景观