在android中压印图像形状(使用EmbossMaskFilter)

时间:2015-02-13 01:44:14

标签: android canvas drawing

我想获得一个基于Path对象创建的浮雕位图。问题是浮雕效果仅适用于直边。

我想得到这样的最终结果:

enter image description here

路径对象创建如下

Path mPath= new Path();

mPath.moveTo(100, 100);
mPath.lineTo(200, 100);
mPath.lineTo(150, 150);
mPath.lineTo(200, 200);
mPath.lineTo(100, 200);
mPath.close();

然后如下从该路径对象创建位图。带浮雕滤镜。

    piecePicture = Bitmap.createBitmap(200, 200,Bitmap.Config.ARGB_8888);

    MaskFilter mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
    Canvas gfx = new Canvas(piecePicture);


    Paint whitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    whitePaint.setColor(Color.WHITE);
    whitePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    whitePaint.setStrokeWidth(1);

    // shape image has to take
    mPath.addRect(10, 10, 195, 195, Direction.CCW);
    gfx.drawPath(mPath, whitePaint);

    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
    paint.setMaskFilter(mEmboss);   
    // draw the image on path viewBgrnd is the bitmap    
    gfx.drawBitmap(viewBgrnd, 10,10, paint);

1 个答案:

答案 0 :(得分:1)

不幸的是,EmbossMaskFilter仅适用于STROKEFILL_AND_STROKE涂料。我无法指出任何有关此问题的文档,但根据我的实验,这些是我可以让它工作的唯一情况。

相关问题