반응형
비트 맵에 굵은 텍스트를 어떻게 그리나요?
굵은 텍스트가있는 비트 맵 아이콘을지도에 그리려고합니다. 이미지에 텍스트를 쓰는 스 니펫이 있습니다.
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
반응형
'program story' 카테고리의 다른 글
사용자 등록시 정의되지 않은 지역 변수 또는 메소드`unconfirmed_email '? (0) | 2020.12.14 |
---|---|
PHP를 통해 이메일로 HTML을 보내시겠습니까? (0) | 2020.12.14 |
각 열에 varchar (MAX)를 사용했지만 CSV 파일을 가져 오는 동안 SQL Server의 오류 (0) | 2020.12.14 |
클래스에 대한 여러 정의가 있습니다. (0) | 2020.12.14 |
Visual Studio Code-VS Code에 여전히 표시되는 GitHub에서 삭제 된 분기를 제거 하시겠습니까? (0) | 2020.12.14 |