2010年3月27日土曜日

Android簡単サンプル【点描画】

【ソース】
package com.naozary.android.example.simple;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class simple extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        setContentView(new GraphicsTestView(this));

    }
}

class GraphicsTestView extends View {
    public GraphicsTestView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(
                Color.argb(
                        255,        // 透明度
                        255,        // Red
                        0,            // Green
                        0            // Blue
                )
        );
      
        canvas.drawPoint(    // 点を描画
                50,            // X座標
                50,            // Y座標
                paint
        );
      

        paint.setColor(    Color.argb(255,0,255,0));
        float[] pts     = {        // 点のデータ
                60,                // 1番目の点-X座標
                60,                // 1番目の点-Y座標
                70,                // 2番目の点-X座標
                70 ,            // 2番目の点-X座標
                80 ,            // 3番目の点-X座標
                80 ,            // 3番目の点-X座標
                90 ,            // 4番目の点-X座標
                90                // 4番目の点-X座標
        };
        canvas.drawPoints(pts, paint);        // 複数の点を描画できる
      
    }
}

【実行結果】

0 件のコメント:

コメントを投稿