회 전자에서 항목을 선택하면 내 그리기 활동 클래스에서 브러시 크기가 변경됩니다. 그러나 이전에 그린 경로의 크기도 변경됩니다. 회 전자에서 모든 선택 항목에 대해 새 페인트 객체를 만들려고했으나 여전히 작동하지 않습니다. 여기서 tv는 draw 메소드가있는 eventTouchView 클래스의 인스턴스입니다. 확실하지 무슨이다 : 내 그리기 활동 클래스에서 내 ViewTouchEvent 클래스에서Android 캔버스/페인트 - Android 캔버스 브러시의 브러시 크기 변경
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
tv.paint= new Paint();
tv.paint.setStyle(Paint.Style.STROKE);
tv.paint.setStrokeJoin(Paint.Join.ROUND);
if (arg0.getSelectedItem().equals("10f")){
tv.paint.setStrokeWidth(10f);
}
else if (arg0.getSelectedItem().equals("20f")){
tv.paint.setStrokeWidth(20f);
}
else if (arg0.getSelectedItem().equals("40f")){
tv.paint.setStrokeWidth(40f);
}
else if (arg0.getSelectedItem().equals("50f")){
tv.paint.setStrokeWidth(50f);
}
else {
tv.paint.setStrokeWidth(30f);
}
}
:
public class ViewTouchEvent extends View{
Paint paint;
Path path = new Path();
protected void onDraw(Canvas canvas){
pathToGrayscale();
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(grayscaleBmp, 0, 100, null);
canvas.drawPath(path, paint);
canvas.drawPath(cursor, cursorPaint);
}
------------------ --------------
새 버전 : 나는 다음 단계를 시도하지만 아래의 코드에 어떤 문제가 확실하다 -
@SuppressLint("DrawAllocation")
protected void onDraw(Canvas canvas){
pathToGrayscale();
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(grayscaleBmp, 0, 100, null);
for (int i =0; i < drawings.size(); i++){
canvas.drawPath(drawings.get(i).getPath(), drawings.get(0).getPaint());
}
//canvas.drawPath(path, paint);
canvas.drawPath(cursor, cursorPaint);
}
public boolean onTouchEvent(MotionEvent event){
float Xpos = event.getX();
float Ypos = event.getY();
//drawings = new Vector<Drawing>();
if (selection == 10){
Drawing draw1 = new Drawing();
draw1.getPaint().setStrokeWidth(10f);
draw1.getPaint().setStyle(Paint.Style.STROKE);
draw1.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw1);
}
else if (selection == 20){
Drawing draw2 = new Drawing();
draw2.getPaint().setStrokeWidth(20f);
draw2.getPaint().setStyle(Paint.Style.STROKE);
draw2.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw2);
}
else if (selection == 30){
Drawing draw3 = new Drawing();
draw3.getPaint().setStrokeWidth(30f);
draw3.getPaint().setStyle(Paint.Style.STROKE);
draw3.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw3);
}
else if (selection == 40){
Drawing draw4 = new Drawing();
draw4.getPaint().setStrokeWidth(40f);
draw4.getPaint().setStyle(Paint.Style.STROKE);
draw4.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw4);
}
else if (selection == 50){
Drawing draw5 = new Drawing();
draw5.getPaint().setStrokeWidth(50f);
draw5.getPaint().setStyle(Paint.Style.STROKE);
draw5.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw5);
}
else{
Drawing draw6 = new Drawing();
draw6.getPaint().setStrokeWidth(70f);
draw6.getPaint().setStyle(Paint.Style.STROKE);
draw6.getPaint().setStrokeJoin(Paint.Join.ROUND);
drawings.add(draw6);
}
//ArrayList <Pair<Float, Float>> pathPixels = new ArrayList <Pair<Float, Float>>();
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
drawings.get(drawings.size()-1).getPath().moveTo(Xpos, Ypos);
xPathPixels.add(Xpos);
yPathPixels.add(Ypos);
//int grayPixel = grayBmp.getPixel(Math.round(Xpos), Math.round(Ypos));
//resizedBmp.setPixel(Math.round(event.getX()), Math.round(event.getY()), grayPixel);
return true;
case MotionEvent.ACTION_MOVE:
drawings.get(drawings.size()-1).getPath().lineTo(Xpos, Ypos);
xPathPixels.add(Xpos);
yPathPixels.add(Ypos);
//pathToGrayscale();
//int grayPixel2 = grayBmp.getPixel(Math.round(Xpos), Math.round(Ypos));
//resizedBmp.setPixel(Math.round(event.getX()), Math.round(event.getY()), grayPixel2);
cursor.reset();
cursor.addCircle(Xpos, Ypos, 30, Path.Direction.CW);
break;
case MotionEvent.ACTION_UP:
//pathToGrayscale();
System.out.println("xPath : " + xPathPixels + " " + "yPath : " + yPathPixels);
cursor.reset();
break;
default:
return false;
}
invalidate();
return true;
}
sdk의 fingerpaint 예제를 따르십시오. – Raghunandan
고마워요! YouTube의 지문 예제? – user37375
android-sdk/samples 아래 – Raghunandan