作者:mobiledu2502918113 | 来源:互联网 | 2023-05-17 21:02
I want to create a bitmap of text with shadow, but I can't get good result. The problem is, when I directly draw the text, it looks good, but when I draw the text to a bitmap, and then draw the bitmap, it looks ugly.
我想创建一个带有阴影的文本的位图,但是我不能得到好的结果。问题是,当我直接绘制文本时,它看起来很好,但是当我把文本绘制到位图时,然后绘制位图,它看起来很难看。
Code:
代码:
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);
}
}
}
When useBitmap
is set to false
, the result looks like this
当useBitmap被设置为false时,结果是这样的。
When useBitmap
is set to true
, the result looks like this
当useBitmap被设置为true时,结果是这样的。
Am I missing something?
我遗漏了什么东西?
1 个解决方案