SignatureView.java 文件源码

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

项目:ResearchStack 作者:
/**
 * 1. Iterating over the path points, saving them in an array ... not bueno. Try to use
 * {@link android.graphics.PathMeasure} class and get minX and minY from that.
 * <p>
 * 2. Scale bitmap down. Currently drawing at density of device.
 */
public Bitmap createSignatureBitmap() {

    Paint bitmapSigPaint = new Paint(sigPaint);
    bitmapSigPaint.setColor(sigPrintColor);

    RectF sigBounds = new RectF();
    sigPath.computeBounds(sigBounds, true);

    if (sigBounds.width() != 0 && sigBounds.height() != 0) {
        float density = getResources().getDisplayMetrics().density;
        int dipWidth = (int) (sigBounds.width() / density);
        int dipHeight = (int) (sigBounds.height() / density);

        Bitmap returnedBitmap = Bitmap.createBitmap(dipWidth, dipHeight,
                Bitmap.Config.ARGB_4444);

        float minX = Integer.MAX_VALUE;
        float minY = Integer.MAX_VALUE;

        for (LinePathPoint point : sigPoints) {
            minX = Math.min(minX, point.x);
            minY = Math.min(minY, point.y);
        }

        sigPath.offset(-minX, -minY);

        PathShape pathShape = new PathShape(sigPath, sigBounds.width(), sigBounds.height());
        pathShape.resize(dipWidth, dipHeight);

        Canvas canvas = new Canvas(returnedBitmap);
        pathShape.draw(canvas, bitmapSigPaint);

        return returnedBitmap;
    }

    return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号