gpt4 book ai didi

android - 创建带有阴影的文本位图

转载 作者:行者123 更新时间:2023-12-02 12:19:06 25 4
gpt4 key购买 nike

我想创建带有阴影的文本位图,但无法获得良好的结果。问题是,当我直接绘制文本时,它看起来不错,但是当我将文本绘制到位图,然后绘制位图时,它看起来很难看。

代码:

public class MyView extends View {
private Paint paint;
private Bitmap bitmap;

public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public void init(){
paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(50);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.create("HELVETICA", Typeface.NORMAL));
paint.setShadowLayer(30, 0, 0, Color.BLACK);

bitmap = Bitmap.createBitmap(500, 300, Bitmap.Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
canvas2.drawText("Dec Use", 100, 100, paint);
}

@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);

final boolean useBitmap = true;
if(useBitmap){
canvas.drawBitmap(bitmap, 0, 0, null);
}
else{
canvas.drawText("Dec Use", 100, 100, paint);
}
}
}

useBitmap设置为false时,结果如下所示

enter image description here

useBitmap设置为true时,结果如下所示

enter image description here

我错过了什么吗?

最佳答案

质量损失似乎与位图有关。通过使用灰色阴影和使用更大的位图可以获得更好的结果(即使这意味着之后需要重新调整)。

    bitmap = Bitmap.createBitmap(2000, 2000, Bitmap.Config.ARGB_8888); 
Canvas canvas2 = new Canvas(bitmap);
canvas2.drawText("Dec Use", 200, 200, paint);

paint.setShadowLayer(20, 0, 0, Color.GRAY);
canvas2.drawText("Dec Use", 200, 200, paint);

enter image description here

Related answer

关于android - 创建带有阴影的文本位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24279600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com