본문 바로가기

Android

캔버스 -AntiAlias

activity_main.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

 

    <com.example.viewex01.MyView4

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"/>

 

</RelativeLayout>

 

 

MainActivity.java

 

package com.example.viewex01;

 

import android.os.Bundle;

 

 

import android.app.Activity;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.view.Menu;

import android.view.View;

 

public class MainActivity2 extends Activity {

 

     @Override

     protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

           setContentView(R.layout.activity_main);

          

     }

    

     @Override

     public boolean onCreateOptionsMenu(Menu menu) {

           // Inflate the menu; this adds items to the action bar if it is present.

           getMenuInflater().inflate(R.menu.main, menu);

           return true;

     }

 

}

 

 

 

MyView3.java

 

package com.example.viewex01;

 

import android.content.Context;

 

 

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.RectF;

import android.util.AttributeSet;

import android.view.View;

 

public class MyView4 extends View {

 

     public MyView4(Context context) {

           super(context);

           // TODO Auto-generated constructor stub

           System.out.println("MyView2(Context context) 호출");

     }

 

     public MyView4(Context context, AttributeSet attrs) {

           super(context, attrs);

           // TODO Auto-generated constructor stub

           System.out.println("MyView2(Context context, AttributeSet attrs) 호출");

     }   

 

     @Override

    

           protected void onDraw(Canvas canvas) {

                // TODO Auto-generated method stub

                //super.onDraw(canvas);

               

               

                Paint pnt = new Paint();

                pnt.setColor(Color.BLACK);

                pnt.setTextSize(30);

               

                //기본 출력

                canvas.drawOval(new RectF(10, 10, 100, 60),pnt);

                canvas.drawText("Text", 110, 40, pnt);

               

                //안티 알리아스 적용

                pnt.setAntiAlias(true);

                canvas.drawOval(new RectF(10, 70, 100, 120), pnt);

                canvas.drawText("Text", 110, 100, pnt);

     }

    

}

 

* Paint pnt = new Paint(Paint.ANTI_ALIAS_FLAG);





'Android' 카테고리의 다른 글

캔버스 - setStyle  (0) 2013.03.29
캔버스 - setStroke  (0) 2013.03.29
캔버스 - 복잡한 도형 그리기  (0) 2013.03.29
캔버스(canvas)  (0) 2013.03.29
이미지 뷰(ImageView) - 이미지 버튼(ImageButton)  (0) 2013.03.28