DocumentGraphic.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:CVScanner 作者:
/**
 * Draw the graphic on the supplied canvas.  Drawing should use the following methods to
 * convert to view coordinates for the graphics that are drawn:
 * <ol>
 * <li>{@link GraphicOverlay.Graphic#scaleX(float)} and {@link GraphicOverlay.Graphic#scaleY(float)} adjust the size of
 * the supplied value from the preview scale to the view scale.</li>
 * <li>{@link GraphicOverlay.Graphic#translateX(float)} and {@link GraphicOverlay.Graphic#translateY(float)} adjust the
 * coordinate from the preview's coordinate system to the view coordinate system.</li>
 * </ol>
 *
 * @param canvas drawing canvas
 */
@Override
public void draw(Canvas canvas) {
    //TODO fix the coordinates see http://zhengrui.github.io/android-coordinates.html

    if(scannedDoc != null && scannedDoc.detectedQuad != null){
        //boolean isPortrait = Util.isPortraitMode(mOverlay.getContext());
        Path path = new Path();

        /*
        Log.d("DOC-GRAPHIC", "IsPortrait? " + isPortrait);

        float tlX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[0].y):translateX((float) scannedDoc.detectedQuad.points[0].x);
        float tlY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[0].x):translateY((float) scannedDoc.detectedQuad.points[0].y);

        Log.d("DOC-GRAPHIC", "Top left: x: " + scannedDoc.detectedQuad.points[0].x + ", y: " + scannedDoc.detectedQuad.points[0].y
                + " -> x: " + tlX + ", y: " + tlY);

        float blX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[1].y):translateX((float) scannedDoc.detectedQuad.points[1].x);
        float blY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[1].x):translateY((float) scannedDoc.detectedQuad.points[1].y);

        Log.d("DOC-GRAPHIC", "Bottom left: x: " + scannedDoc.detectedQuad.points[1].x + ", y: " + scannedDoc.detectedQuad.points[1].y
                + " -> x: " + blX + ", y: " + blY);

        float brX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[2].y):translateX((float) scannedDoc.detectedQuad.points[2].x);
        float brY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[2].x):translateY((float) scannedDoc.detectedQuad.points[2].y);

        Log.d("DOC-GRAPHIC", "Bottom right: x: " + scannedDoc.detectedQuad.points[2].x + ", y: " + scannedDoc.detectedQuad.points[2].y
                + " -> x: " + brX + ", y: " + brY);

        float trX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[3].y):translateX((float) scannedDoc.detectedQuad.points[3].x);
        float trY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[3].x):translateY((float) scannedDoc.detectedQuad.points[3].y);

        Log.d("DOC-GRAPHIC", "Top right: x: " + scannedDoc.detectedQuad.points[3].x + ", y: " + scannedDoc.detectedQuad.points[3].y
                + " -> x: " + trX + ", y: " + trY);
        */
        int frameWidth = scannedDoc.getImage().getMetadata().getHeight();

        path.moveTo(((float)(frameWidth - scannedDoc.detectedQuad.points[0].y)), ((float)scannedDoc.detectedQuad.points[0].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[1].y)), ((float)scannedDoc.detectedQuad.points[1].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[2].y)), ((float)scannedDoc.detectedQuad.points[2].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[3].y)), ((float)scannedDoc.detectedQuad.points[3].x));
        path.close();

        PathShape shape = new PathShape(path, scannedDoc.getImage().getMetadata().getHeight(), scannedDoc.getImage().getMetadata().getWidth());
        shape.resize(canvas.getWidth(), canvas.getHeight());

        shape.draw(canvas, bodyPaint);
        shape.draw(canvas, borderPaint);

        //canvas.drawPath(path, borderPaint);
        //canvas.drawPath(path, bodyPaint);

        Log.d("DOC-GRAPHIC", "DONE DRAWING");
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号