我想創建一個帶有陰影的文本位圖,但我無法獲得好的結果。問題是,當我直接繪製文本時,它看起來不錯,但是當我將文本繪製到位圖,然後繪製位圖時,它看起來很難看。創建一個帶有陰影的文本位圖
代碼:
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
,結果看起來像這樣
當useBitmap
設置爲true
,結果看起來像這樣
我錯過了什麼嗎?
有人找到解決辦法? – dakshbhatt21