在背景图片绘画文本暗淡 [英] Painting text over background image is dim

查看:222
本文介绍了在背景图片绘画文本暗淡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在一个画布上的背景图像绘画文本。我移动图像交互(如显灵板指针)。我设置画布为黑色,指针是红色的,我想要写白字在它使指针有玩家就可以了名字。

I'm painting text over a background image on a canvas. I move the image interactively (like a Ouija board pointer). I've set the canvas to black, the pointer is red and I want to write white text over it so that the pointer has a player's name on it.

在的Andr​​oid 2.3.4它出现在红色指针是pretty明确的顶部为纯白色的文字,但我想用任何颜色。在Android中4.1.2我可以勉强看到白色文本。这里是我的code:

In Android 2.3.4 it appears as solid white text on top of the red pointer which is pretty clear, but I'd like to use any color. In Android 4.1.2 I can barely see the white text. Here's my code:

    public Pointer(Context context) {
    super(context);

    paintBg = new Paint();
    paintBg.setColor(Color.BLACK);
    paintName = new Paint();
    paintName.setColor(Color.WHITE);
    paintName.setTextSize(50); // set text size
    paintName.setStrokeWidth(5);
    paintName.setTextAlign(Paint.Align.CENTER);

    this.setImageResource(res); // pointer.png in res/drawable folder
    Drawable d = getResources().getDrawable(res);
    h = d.getIntrinsicHeight();
    w = d.getIntrinsicWidth();

    canvas = new Canvas();
    canvas.drawPaint(paintBg);//make background black

    // float imageScale = width / w; // how image size scales with screen
}


@Override
public void onDraw(Canvas canvas) {

    y = this.getHeight() / 2; // center of screen
    x = this.getWidth() / 2;
    int left = Math.round(x - 0.8f * w);
    int right = Math.round(x + 0.8f * w);

    canvas.save();
    canvas.rotate((direction + 180) % 360, x, y); // rotate to normal
    canvas.drawText(s, x, y + 20, paintName); // draw name

    canvas.restore();
    canvas.rotate(direction, x, y); // rotate back
    super.onDraw(canvas);
}

在什么改变4.1.2会影响这一点,还是我doning什么错误?感谢您与此的帮助,因为它的驾驶我疯了。

What changed in 4.1.2 that would affect this, or am I doning something incorrectly? Thanks for your help with this as it's driving me crazy.

编辑,包括屏幕截图:

Android的2.3.4结果

Android 2.3.4

4.1.2的Andr​​oid

Android 4.1.2

请注意白字的显示方式在上面的2.3.4,而它下面或泥泞出现在4.1.2。

Note how the white text appears to be on top in 2.3.4 while it appears below or muddy in 4.1.2.

由于free3dom pointes的出它关系到阿尔法。我改变阿尔法,因为如果我不这样做,文字没有箭头的顶部出现。看来,具有指针图像的ImageView的是总在最前面 - 难道这是怎么回事?
这里是我如何处理设置阿尔法:

As free3dom pointes out it is related to alpha. I do change alpha because if I don't, the text does not appear on top of the arrow. It appears that the ImageView having the pointer image is always on top - could this be what's going on? Here is how I handle setting alpha:

    public static void setAlpha(View view, float alpha, int duration) {
if (Build.VERSION.SDK_INT < 11) {
    final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
    animation.setDuration(duration);
    animation.setFillAfter(true);
    view.startAnimation(animation);
 } else                          //for 11 and above
    view.setAlpha(alpha);
}

或许这是与使用this.setImageResource(RES)来设置图像资源?据Android开发者指南,我只能设置阿尔法的单一视图,一切都在视图中被改变。然而,如果我降低阿尔法,箭头形象似乎变得足够透明的,让我看到的文字。

Maybe it has something to do with using this.setImageResource(res) to set the image resource? According to android developer guide, I can only set alpha to the single view and everything in the view is changed. Yet if I lower the alpha, the arrow image seems to become transparent enough to allow me to see the text.

推荐答案

您设置描边宽度,但从未表示行程应该用于油漆

You set a stroke width, but never indicate that stroke should be used for the Paint.

尝试增加

paintName.setStyle(FILL_AND_STROKE);

这篇关于在背景图片绘画文本暗淡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆