0

私は描画アプリのようなアプリをやっています...すべてがうまくいっています..しかし、今私は鉛筆の幅を追加したい..

そのために私はやった

mPaint.setStrokeWidth(seekbarvalue);

しかし、問題は、それが飽きのこない図面に適用されることですが、次の図面にのみ適用したいのですが...どうすればよいですか?

私のコードは

private void touch_start(float x, float y) {
            mPath.reset();
            mPath.moveTo(x, y);
            mX = x;
            mY = y;

        }

        private void touch_move(float x, float y) {
            float dx = Math.abs(x - mX);
            float dy = Math.abs(y - mY);
            if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
                mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
                mX = x;
                mY = y;
            }
        }

        private void touch_up() {
            mPath.lineTo(mX, mY);

            // commit the path to our offscreen
            mCanvas.drawPath(mPath, mPaint);
            // kill this so we don't double draw
            mPath = new Path();
            paths.add(new PathPoints(mPath, color, false));

        }

        private void drawText(int x, int y) {
            Log.v(TAG, "Here");
            Log.v(TAG, "X " + x + " Y " + y);
            this.x = x;
            this.y = y;
            paths.add(new PathPoints(color, textToDraw, true, x, y));
            // mCanvas.drawText(textToDraw, x, y, mPaint);
        }

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            isTouched = true;
            float x = event.getX();
            float y = event.getY();

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (!isTextModeOn) {
                    touch_start(x, y);
                    invalidate();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (!isTextModeOn) {
                    touch_move(x, y);
                    invalidate();
                }
                break;
            case MotionEvent.ACTION_UP:
                if (isTextModeOn) {
                    drawText((int) x, (int) y);
                    invalidate();
                } else {
                    touch_up();
                    invalidate();
                }
                break;
            }
            return true;
        }

そしてこれがシークバー

sekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                if (fromUser) {

                 mPaint.setStrokeWidth(progress);
                }
            }
        });

ただし、図面全体に適用されます

これは私の ondraw mwthod です

protected void onDraw(Canvas canvas1) {
            canvas = canvas1;

            // === canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
            invalidate();
            mPaint.setStrokeWidth(GlobalVar.getSeekvalue());
            invalidate();
            canvas.drawBitmap(Transparent, 0, 0, mBitmapPaint);
            c2.drawBitmap(Bitmap2, 0, 0, mBitmapPaint);
            // canvas.drawBitmap(Transparent, 0, 0, mBitmapPaint);
            // canvas.drawBitmap(Transparent, 0, 0, null);
            // c2.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
            for (PathPoints p : paths) {
                mPaint.setColor(p.getColor());

                Log.v("", "Color code : " + p.getColor());
                if (p.isTextToDraw()) {
                    canvas.drawText(p.textToDraw, p.x, p.y, mPaint);
                } else {
                    // if(isTouched)
                    // {
                    // canvas.drawPath(p.getPath(), mPaint);

                    c2.drawPath(p.getPath(), mPaint);

私は何をする必要がありますか?

4

2 に答える 2

1

PathPoint オブジェクトに別のフィールドを設定し、strokWidth と名前を付けます。

private void touch_up() {
        mPath.lineTo(mX, mY);
        int strokWidth = GlobalVar.getSeekvalue();  
        // commit the path to our offscreen
        mPaint.setStrokeWidth(strokWidth);
        mCanvas.drawPath(mPath, mPaint);
        // kill this so we don't double draw
        mPath = new Path();
        paths.add(new PathPoints(mPath, color, false));

    }

そして毎回変わる

paths.add(new PathPoints(mPath, color, false));

paths.add(new PathPoints(mPath, color, false,strokWidth));

ondraw メソッドと for ループで:

for (PathPoints p : paths) {
            mPaint.setColor(p.getColor());
            mPaint.setStrokeWidth(p.getStrokWidth());

今、これらの行は役に立たないと思います:

invalidate();
mPaint.setStrokeWidth(GlobalVar.getSeekvalue());
invalidate();
于 2014-08-07T08:21:36.503 に答える
1

さまざまなストロークで塗料のプールを使用できます (重要:) それを個別の部品にします。幅は 4px、8px、12px、14px、18px、22px です。

 Paint basePaint=new Paint();

 SparseArray<Paint>poolPaint=new SparseArray<Paint>();

 Paint currPaint; //<- that's your paint that change width stroke on progressbar seek




 sekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
             // make it discrete not like here for every single width is not worthy
            int widthPaint=progress;
            if (fromUser) {
                if((currPaint=poolPaint.get(widthPaint))==null){
                      Paint newPaint=  new Paint(basePaint).setStrokeWidth(widthPaint)
                      poolPaint.put(widthPaint,newPaint);
                      currPaint=newPaint;  
                 }


            }
        }
    });
于 2014-08-07T07:54:16.357 に答える