본문 바로가기

Android

그리기 객체 - 텍스트

 

package com.example.viewex01;

 

import android.content.Context;

 

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.RectF;

import android.graphics.Typeface;

import android.view.View;

 

public class MyView9 extends View {

 

     public MyView9(Context context) {

           super(context);

           // TODO Auto-generated constructor stub

 

     }

 

     @Override

     public void onDraw(Canvas canvas) {

           canvas.drawColor(Color.LTGRAY);

           Paint Pnt = new Paint();

           String str = "Made in Korea";

           char[] arCh = { 'a', 'b', 'c' };

           // 기본문자열출력. 안티알리아싱을적용했다.

           Pnt.setAntiAlias(true);

           Pnt.setColor(Color.BLACK);

           canvas.drawText(str, 10, 20, Pnt);

           canvas.drawText(str, 2, 11, 10, 40, Pnt);

           canvas.drawText(arCh, 0, 3, 10, 60, Pnt);

           // 수평정렬

           Pnt.setTextAlign(Paint.Align.LEFT);

           canvas.drawText("Left Align", 100, 90, Pnt);

           Pnt.setTextAlign(Paint.Align.CENTER);

           canvas.drawText("Center Align", 100, 110, Pnt);

           Pnt.setTextAlign(Paint.Align.RIGHT);

           canvas.drawText("Right Align", 100, 130, Pnt);

           // 수직정렬은항상글꼴의베이스에맞춰짂다.

           Pnt.setTextAlign(Paint.Align.LEFT);

           Pnt.setColor(Color.RED);

           canvas.drawText("Small", 10, 180, Pnt);

           Pnt.setTextSize(20);

           canvas.drawText("Mid", 40, 180, Pnt);

           Pnt.setTextSize(30);

           canvas.drawText("Big", 80, 180, Pnt);

           Pnt.setTextSize(40);

           canvas.drawText("Hy", 125, 180, Pnt);

           // 여러가지속성동시에적용해보기

           Pnt.setColor(Color.BLUE);

           Pnt.setTextAlign(Paint.Align.LEFT);

           Pnt.setTextSize(30);

           Pnt.setTypeface(Typeface.create((String) null, Typeface.BOLD));

           Pnt.setUnderlineText(true);

           Pnt.setStrikeThruText(true);

           Pnt.setSubpixelText(true);

           Pnt.setTextSkewX(-0.25f);

           Pnt.setTextScaleX(0.8f);

           canvas.drawText(str, 10, 220, Pnt);

     }

 

}

 



 

'Android' 카테고리의 다른 글

그리기 객체 - 텍스트 FreeType라이브러리  (0) 2013.03.29
그리기 객체 - 택스트 Typeface  (0) 2013.03.29
그리기 객체 - Bitmap  (0) 2013.03.29
캔버스 - setStyle  (0) 2013.03.29
캔버스 - setStroke  (0) 2013.03.29