4

Picture beginRecording() メソッドからの Canvas があります。
キャンバスに記録してから endRecording() を呼び出します。
キャンバスが後で拡大縮小されたときに拡大縮小されないストロークを記録できるようにしたいと思います。
Paint クラスではそのようなものは見られません。StrokeWidth(float w) を設定できますが、
- w == 0 の場合、必要な機能のようなものがありますが、1px のみです
- w != 0 の場合、キャンバスのスケーリングはストロークのスケーリングも意味します。
何か案は?

4

4 に答える 4

2

現在の変換マトリックスからスケールを抽出し、その逆数を使用してストローク幅を設定します。

于 2011-11-15T13:35:36.257 に答える
0

ソリューションにはクラスの拡張が含まれているため、詳細を投稿します。私はそれを広範囲にテストしていませんが、必要なコンテキストでのみテストしています。
Picture.recording() が機能する方法のように、アクションのリストから Drawable を取得したかったのです。
幸いなことに、Path オブジェクトはアクションを記録できるので、それらをキャンバスにペイントできます。
残念ながら、 canvas.drawPath() を介してペイントしても、スケーリングなしのストローク機能は提供されません。

@Andrew からのヒントのおかげで、PathShape と同様に Shape を拡張しましたが、onResize() にいくつかの異なるロジックを使用しました。

public class NonScalingStrokePathShape extends Shape{
    private Path    mPath;
    private float   mInitialWidth;
    private float   mInitialHeight;
    private float   mCurrentWidth;    
    private float   mCurrentHeight;    

    public NonScalingStrokePathShape(Path pPath, float pInitialWidth, float pInitialHeight) {
        mPath = pPath;
        mInitialWidth = pInitialWidth;
        mInitialHeight = pInitialHeight;
        mCurrentWidth = mInitialWidth;
        mCurrentHeight = mInitialHeight;
    }

    @Override
    public void draw(Canvas canvas, Paint paint) {
        canvas.drawPath(mPath,paint);
    }

    @Override
    protected void onResize(float width, float height) {
        Matrix matrix = new Matrix();
        matrix.setScale(width / mCurrentWidth, height / mCurrentHeight);
        mCurrentWidth = width;
        mCurrentHeight = height;
        mPath.transform(matrix);
    }

    @Override
    public NonScalingStrokePathShape clone() throws CloneNotSupportedException {
        NonScalingStrokePathShape shape = (NonScalingStrokePathShape) super.clone();
        shape.mPath = new Path(mPath);
        shape.mInitialHeight =  mInitialHeight;
        shape.mInitialWidth = mInitialWidth;
        shape.mCurrentWidth = mInitialWidth;
        shape.mCurrentHeight = mInitialHeight;
        return shape;
    }

}

これは、Shape resize(float w, float h) メソッドを呼び出すことによって境界のサイズ変更を既に考慮している Drawable である ShapeDrawable で使用できます。

于 2011-11-15T14:41:49.673 に答える
0

You will probably need to keep track of your width in a custom SVG object. As the object is scaled you can find the ratio between the new width and that of the initial size and multiply that to your initial stroke width. It doesn't have to be width, it could very much well be height or diagonal. It depends on how your object is scaling.

Or you could see if this already does what you want:

http://code.google.com/p/svg-android/

于 2011-11-14T13:45:44.737 に答える
0

これはばかげた答えです:

w = 0 を並べてストロークを X 回描画します。

于 2011-11-14T13:28:48.070 に答える