我试图绘制表情符号,每当我触摸屏幕时,我都在使用setShader
方法和BitmapShader
来制作表情符号,但是下面的代码给出了这一点:
public class MainActivity extends Activity implements View.OnTouchListener{
float downx = 0;
float downy = 0;
float upx = 0;
float upy = 0;
Canvas canvas;
Paint paint;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Point point = new Point();
Display cureentDispaly = getWindowManager().getDefaultDisplay();
cureentDispaly.getSize(point);
int weidth = point.x;
int height = point.y;
Bitmap bitmap = Bitmap.createBitmap(weidth , height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(50);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(),R.drawable.heart), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
paint.setStyle(Paint.Style.STROKE);
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
downx = event.getX();
downy = event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
}
我想要的东西与此Draw With Emoji和以下内容类似:
如何在不裁剪的情况下绘制重复的表情符号
?