问题描述
在我的画布应用程序,我想使用自定义画笔一样附着刷image.so请别人帮我快,我怎么能自定义画笔一样附着的形象?
In my canvas application i want to use custom brushes like brushes in attached image.so please somebody help me fast how can i make custom brushes like attached image?
在我的应用程序使用我下面code发点线:
In my app i made doted line using following code:
mPaint.setPathEffect(new DashPathEffect(new float[] { 8, 8 }, 0));
和获得使用下面的code模糊和浮雕效果:
and getting Blur and Emboss effect using following code:
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
推荐答案
正如你可以清楚地看到,没有琐碎的着色效果/矩形/圆圈可以做到这一点。图像/位图使用。
As you can clearly see, no trivial shader effects / rectangles / circles can accomplish this.Images / Bitmaps are used.
所以,简单地重复使用位图绘制 canvas.drawBitmap
。你一次又一次地得出同样的位图,而手指的移动。
So simply repeatedly draw Bitmaps using canvas.drawBitmap
. You draw the same Bitmap again and again while the finger moves.
有关添加自定义颜色,您可以添加一个简单的过滤器。
For adding a custom color you can add a simple filter.
public class CanvasBrushDrawing extends View {
private Bitmap mBitmapBrush;
private Vector2 mBitmapBrushDimensions;
private List<Vector2> mPositions = new ArrayList<Vector2>(100);
private static final class Vector2 {
public Vector2(float x, float y) {
this.x = x;
this.y = y;
}
public final float x;
public final float y;
}
public CanvasBrushDrawing(Context context) {
super(context);
// load your brush here
mBitmapBrush = BitmapFactory.decodeResource(context.getResources(), R.drawable.splatter_brush);
mBitmapBrushDimensions = new Vector2(mBitmapBrush.getWidth(), mBitmapBrush.getHeight());
setBackgroundColor(0xffffffff);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (Vector2 pos : mPositions) {
canvas.drawBitmap(mBitmapBrush, pos.x, pos.y, null);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
final float posX = event.getX();
final float posY = event.getY();
mPositions.add(new Vector2(posX - mBitmapBrushDimensions.x / 2, posY - mBitmapBrushDimensions.y / 2));
invalidate();
}
return true;
}
}
这篇关于如何使自定义画笔在Android的印刷品吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!