我尝试使用EmbossMaskFilter来创建自定义Drawable。 然而,我遇到了奇怪的行为,当我尝试使用浮雕时,它会导致 其他2d图形对象边缘的黑色条纹与“浮雕”的绘图边界重叠。
我错过了什么吗?也许是一些〜像素混合设置或什么?
示例: ScrollView“fadings”上的黑色条纹。 当我移除浮雕面具时,它们就消失了。 此外,当我使用Emboss制作带有背景可绘制的ImageButton并使用前面可绘制作为画布绘图时,这个前面的drawable也会获得条纹。
活动(+ main.xml = ScrollView中的LinearLayout = http://pastebin.com/031AV6Wp):
public class TestEmbossActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setMaskFilter(new BlurMaskFilter(15, Blur.INNER));
paint.setMaskFilter(new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 5, 3f));
ViewGroup container = (ViewGroup) findViewById(R.id.container);
for(int i = 0; i < 20; i++) {
ImageView view = new ImageView(this);
view.setScaleType(ScaleType.FIT_XY);
Drawable drawable = new MyDrawable(paint);
view.setImageDrawable(drawable);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100, 100);
params.bottomMargin = 10;
container.addView(view, params);
}
}
private static class MyDrawable extends Drawable {
Paint paint;
private MyDrawable(Paint paint) {
this.paint = paint;
}
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
canvas.drawRect(bounds, paint);
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
public void setAlpha(int alpha) {
// TODO Auto-generated method stub
}
@Override
public void setColorFilter(ColorFilter cf) {
// TODO Auto-generated method stub
}
}
}