私は描画アプリのようなアプリをやっています...すべてがうまくいっています..しかし、今私は鉛筆の幅を追加したい..
そのために私はやった
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);
私は何をする必要がありますか?