program story

비트 맵에 굵은 텍스트를 어떻게 그리나요?

inputbox 2020. 12. 14. 08:09
반응형

비트 맵에 굵은 텍스트를 어떻게 그리나요?


굵은 텍스트가있는 비트 맵 아이콘을지도에 그리려고합니다. 이미지에 텍스트를 쓰는 스 니펫이 있습니다.

Bitmap icon = BitmapFactory.decodeResource(PropertyMapList.this.getResources(),
        R.drawable.location_mark);
TextPaint paint = new TextPaint();
paint.setColor(Color.BLACK);
paint.setTextSize(14);
paint.setFakeBoldText(true);
//paint.setTextAlign(Align.CENTER);
Bitmap copy = icon.copy(Bitmap.Config.ARGB_8888, true); 
Canvas canvas = new Canvas(copy);
//canvas.drawText(jsonObj.getString("district_name"), 5, canvas.getHeight()/2, paint);
String districtName = jsonObj.getString("district_name");
StaticLayout layout = new StaticLayout((districtName.length()>25 ? districtName.substring(0, 24)+"..":districtName)+"\n"+jsonObj.getString("total_properties"), paint, canvas.getWidth()-10,Layout.Alignment.ALIGN_CENTER, 1.3f, 0, false);
canvas.translate(5, canvas.getHeight()/2); //position the text
layout.draw(canvas);

setFakeBoldText(true)나를 위해 작동하지 않습니다. 비트 맵에 그려진 텍스트를 굵게 표시하고 싶습니다.


개체 에서 setTypeface방법을 사용하여 Paint굵은 스타일이 설정된 글꼴로 설정합니다.

paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));

사용자 정의 글꼴의 경우 :

Typeface typeface = Typeface.create(Typeface.createFromAsset(mContext.getAssets(), "fonts/bangla/bensen_handwriting.ttf"), Typeface.BOLD);

일반 글꼴의 경우 :

Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD);

그리고

paint.setTypeface(typeface);

참고 URL : https://stackoverflow.com/questions/17926522/how-do-i-draw-bold-text-on-a-bitmap

반응형