Paint 属性在应用两次时不起作用
Paint attributes do not work when applied twice
我正在尝试创建具有白色和黑色轮廓的自定义效果字体(又名 "meme font")。我在 canvas 的两端都有 2 个文本,但其中只有一个反映了更改。这是到目前为止我所拥有的:
这是我的代码:
Canvas canvas = new Canvas(mutableBitmap);
TextPaint topFillPaint = new TextPaint();
TextPaint bottomFillPaint = new TextPaint();
TextPaint topStrokePaint = new TextPaint();
TextPaint bottomStrokePaint = new TextPaint();
Typeface typeface = getResources().getFont(R.font.impact);
topFillPaint.setColor(Color.WHITE);
topFillPaint.setTextSize(topTextView.getTextSize());
topFillPaint.setTypeface(typeface);
topStrokePaint.setStyle(Paint.Style.STROKE);
topStrokePaint.setStrokeWidth(8);
topStrokePaint.setColor(Color.BLACK);
topStrokePaint.setTextSize(topTextView.getTextSize());
topStrokePaint.setTypeface(typeface);
bottomFillPaint.setColor(Color.WHITE);
bottomFillPaint.setTextSize(bottomTextView.getTextSize());
bottomFillPaint.setTypeface(typeface);
bottomStrokePaint.setStyle(Paint.Style.STROKE);
bottomStrokePaint.setStrokeWidth(8);
bottomStrokePaint.setColor(Color.BLACK);
bottomStrokePaint.setTextSize(bottomTextView.getTextSize());
bottomStrokePaint.setTypeface(typeface);
float topTextMeasurement = topFillPaint.measureText(topText);
float bottomTextMeasurement = bottomFillPaint.measureText(bottomText);
StaticLayout topFillLayout = new StaticLayout(topText, topFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout topStrokeLayout = new StaticLayout(topText, topStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout bottomFillLayout = new StaticLayout(bottomText, bottomFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout bottomStrokeLayout = new StaticLayout(bottomText, bottomStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
canvas.translate(0,0);
topFillLayout.draw(canvas);
canvas.translate(0,0);
topStrokeLayout.draw(canvas);
canvas.translate(0, canvas.getHeight() - 210);
bottomFillLayout.draw(canvas);
canvas.translate(0, canvas.getHeigth() - 210);
bottomStrokeLayout.draw(canvas);
您传递给绘制 bottomStrokeLayout 和 bottomFillLayout 的坐标不同。
canvas.translate(0, canvas.getHeight() - 210);
bottomFillLayout.draw(canvas);
canvas.translate(0,canvas.getHeight() -210);
bottomStrokeLayout.draw(canvas);
我正在尝试创建具有白色和黑色轮廓的自定义效果字体(又名 "meme font")。我在 canvas 的两端都有 2 个文本,但其中只有一个反映了更改。这是到目前为止我所拥有的:
这是我的代码:
Canvas canvas = new Canvas(mutableBitmap);
TextPaint topFillPaint = new TextPaint();
TextPaint bottomFillPaint = new TextPaint();
TextPaint topStrokePaint = new TextPaint();
TextPaint bottomStrokePaint = new TextPaint();
Typeface typeface = getResources().getFont(R.font.impact);
topFillPaint.setColor(Color.WHITE);
topFillPaint.setTextSize(topTextView.getTextSize());
topFillPaint.setTypeface(typeface);
topStrokePaint.setStyle(Paint.Style.STROKE);
topStrokePaint.setStrokeWidth(8);
topStrokePaint.setColor(Color.BLACK);
topStrokePaint.setTextSize(topTextView.getTextSize());
topStrokePaint.setTypeface(typeface);
bottomFillPaint.setColor(Color.WHITE);
bottomFillPaint.setTextSize(bottomTextView.getTextSize());
bottomFillPaint.setTypeface(typeface);
bottomStrokePaint.setStyle(Paint.Style.STROKE);
bottomStrokePaint.setStrokeWidth(8);
bottomStrokePaint.setColor(Color.BLACK);
bottomStrokePaint.setTextSize(bottomTextView.getTextSize());
bottomStrokePaint.setTypeface(typeface);
float topTextMeasurement = topFillPaint.measureText(topText);
float bottomTextMeasurement = bottomFillPaint.measureText(bottomText);
StaticLayout topFillLayout = new StaticLayout(topText, topFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout topStrokeLayout = new StaticLayout(topText, topStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout bottomFillLayout = new StaticLayout(bottomText, bottomFillPaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
StaticLayout bottomStrokeLayout = new StaticLayout(bottomText, bottomStrokePaint, canvas.getWidth(), Layout.Alignment.ALIGN_CENTER,
1.0f, 0.0f, false);
canvas.translate(0,0);
topFillLayout.draw(canvas);
canvas.translate(0,0);
topStrokeLayout.draw(canvas);
canvas.translate(0, canvas.getHeight() - 210);
bottomFillLayout.draw(canvas);
canvas.translate(0, canvas.getHeigth() - 210);
bottomStrokeLayout.draw(canvas);
您传递给绘制 bottomStrokeLayout 和 bottomFillLayout 的坐标不同。
canvas.translate(0, canvas.getHeight() - 210);
bottomFillLayout.draw(canvas);
canvas.translate(0,canvas.getHeight() -210);
bottomStrokeLayout.draw(canvas);