0

座標でキャンバスを描画し、それらを一緒に画像に合わせて拡大縮小するにはどうすればよいですか? 1.画像側では、色付きのポリゴンは背景画像に合わせて拡大縮小する必要がありますが、そうではありません。(正しい位置に表示されます) 2. polygonList には座標が含まれており、スケーリング時に値を変更する必要があるため、クリック位置がポロゴン内にある場合は onSigleTabEvent を見つけることができます。しかし、座標が常に無限大になるため、現在は機能していません。 (解決しました!)

PS: TouchImageView は XML ファイルに埋め込まれています。TouchImageView .java の onDraw メソッド

@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas);

    if (polygonList != null) {
        for (Polygon polygon : polygonList) {
            canvas.drawPath(polygon.path, polygon.paint);
        }
    }
    onDrawReady = true;
    imageRenderedAtLeastOnce = true;
    if (delayedZoomVariables != null) {
        setZoom(delayedZoomVariables.scale, delayedZoomVariables.focusX,
             delayedZoomVariables.focusY,
            delayedZoomVariables.scaleType);
        delayedZoomVariables = null;
    } 
}

private void fixTrans() {
    matrix.getValues(m);
    // update all polygon coordinate
    for (Polygon polygon : polygonList) {
        for (Coordinate coordinate : polygon.coordinates) {
            coordinate.x = coordinate.x * m[0] + m[2];
            coordinate.y = coordinate.y * m[4] + m[5];
        }
    }

    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];

    float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
    float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

    if (fixTransX != 0 || fixTransY != 0) {
        matrix.postTranslate(fixTransX, fixTransY);
    }
} 

MainActivity.java

場所のリスト = floorPlan.getLocation(); Log.i("FloorPlanAct", "SetupClickArea(), Location.count():" + locations.size()); リスト polygonList = new ArrayList<>();

for (Location location : locations) {

    List<Coordinate> coordinateList = location.getCoordinate();
    // Test data, has location, but no coordinate

    // Paint as a pen
    Paint paint = new Paint();
    paint.setARGB(location.areaColorA, location.areaColorR,              
    location.areaColorG, location.areaColorB);
    paint.setAlpha(128);
    paint.setStyle(Paint.Style.FILL);

    // Group pen and path as a Polygon~
    Polygon polygon = new Polygon(coordinateList, paint, location);
    polygonList.add(polygon);
}

// 1. Prepare originalImagePosition
preparePolygon(polygonList, obj.orignalMatrix);

// Create a click area
TouchImageView imgClickArea = holder.imgClickArea;
imgClickArea.init(act, polygonList, obj.scaledBitmap, obj.orignalMatrix);

public void preparePolygon(List<Polygon> polygonList, Matrix
         orignalMatrix){

    float[] m = new float[9];
    orignalMatrix.getValues(m);

    for (Polygon polygon : polygonList) {
        List<Coordinate> coordinates = polygon.coordinates;

        // Path walk follow the coordinate
        Path path = new Path();
        path.reset(); // only needed when reusing this path for a new build
        int coordinateCount = coordinates.size();
        Log.i("TouchImageView", "***** initPolygon(), Polygon ******");

        for (int i = 0; i < coordinateCount; i++) {

            // Calculate the point of screen
            Coordinate coordinate = coordinates.get(i);
            Log.i("TouchImageView", "**** Coordinate ****");
            Log.i("TouchImageView", "Original :" + coordinate.x + "," + coordinate.y);

            coordinate.x = coordinate.x * m[0] + m[2];
            coordinate.y = coordinate.y * m[4] + m[5];
            Log.i("TouchImageView", "On the screen:" + coordinate.x + "," + coordinate.y);

            if (i == 0) {
                path.moveTo(coordinate.x, coordinate.y);
            } else {
                path.lineTo(coordinate.x, coordinate.y);
            }
        }

        path.close();
        polygon.path = path;
    }
}
4

0 に答える 0