본문 바로가기

Android

셰이더 - 원형 그래디언트 RadialGradient

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.LinearGradient;

import android.graphics.Paint;

import android.graphics.Path;

import android.graphics.RadialGradient;

import android.graphics.RectF;

import android.graphics.Shader.TileMode;

import android.graphics.Typeface;

import android.view.View;

 

public class MyView14 extends View {

    

    

     public MyView14(Context context) {

           super(context);

           // TODO Auto-generated constructor stub

          

          

     }

 

     @Override

     public void onDraw(Canvas canvas) {

           Paint Pnt= new Paint();

           Pnt.setAntiAlias(true);

           int[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.WHITE};

           float[] pos = { 0.0f, 0.1f, 0.6f, 0.9f, 1.0f };

           // 파란색흰색

           Pnt.setShader(new RadialGradient(80, 80, 70,

           Color.BLUE, Color.WHITE, TileMode.CLAMP));

           canvas.drawCircle(80, 80, 70, Pnt);

           // 흰색파란색

           Pnt.setShader(new RadialGradient(230, 80, 70,

           Color.WHITE, Color.BLUE, TileMode.CLAMP));

           canvas.drawCircle(230, 80, 70, Pnt);

           // 여러가지색균등

           Pnt.setShader(new RadialGradient(80, 230, 70, colors, null, TileMode.CLAMP));

           canvas.drawCircle(80, 230, 70, Pnt);

           // 여러가지색차등

           Pnt.setShader(new RadialGradient(230, 230, 70, colors, pos, TileMode.CLAMP));

           canvas.drawCircle(230, 230, 70, Pnt);

           }

 

}