안드로이드

 

 

 

 

 

 

 

 

class CustomView
package com.example.choi.customview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class CustomView extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Custom customView =new Custom(CustomView.this);
        setContentView(customView);

    }



}

 

class Custom
package com.example.choi.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

/**
 * Created by choi on 2017-03-03.
 */

public class Custom extends View {

    public Custom(Context context) {
        super(context);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //배경색
        canvas.drawColor(Color.rgb(236,121, 47));

        Paint paint =new Paint();

        paint.setColor(Color.RED);
        canvas.drawPoint(110, 110 , paint);

        paint.setColor(Color.YELLOW);
        canvas.drawLine(50,50 ,100, 100, paint);

        paint.setColor(Color.BLUE);
        canvas.drawRect(150, 10, 250, 150, paint);

        paint.setColor(0x5000ffff);
        canvas.drawCircle(200, 200, 100, paint);

    }








}

 

 

 

 

 class MyBitmap
package com.example.choi.customview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MyBitmap extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        BitmapCanvas bitmapView =new BitmapCanvas(MyBitmap.this);
        setContentView(bitmapView);
    }


}

 

class BitmapCanvas
package com.example.choi.customview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Shader;
import android.view.View;

/**
 * Created by choi on 2017-03-03.
 */

public class BitmapCanvas extends View {


    public BitmapCanvas(Context context) {
        super(context);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.LTGRAY);

        Paint paint =new Paint();
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.eyes);


        //이미지 사이즈 조절
        float width = bitmap.getWidth();
        float height = bitmap.getHeight();
        Bitmap sizingBmp = Bitmap.createScaledBitmap(bitmap, (int) width/3, (int) height/2, true);

        canvas.drawBitmap(sizingBmp, 10, 10 ,paint);




        //이미지 반복 패터
        Paint paint2 = new Paint();
        paint.setAntiAlias(true);

        Bitmap bitmap2 = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.eyes);

//		paint.setShader(new BitmapShader(bitmap, TileMode.REPEAT, TileMode.CLAMP));
//		paint.setShader(new BitmapShader(bitmap, TileMode.REPEAT, TileMode.MIRROR));
        Bitmap sizingBmp2 = Bitmap.createScaledBitmap(bitmap, (int) width/20, (int) height/20, true);
        paint.setShader(new BitmapShader(sizingBmp2, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
        canvas.drawRect(0, 450, 800, 800, paint);

    }


}




 

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

여성이 술을 한 잔 마시는 것은 퍽 좋은 일이다. 두 잔 마시면 그녀는 품위를 떨어뜨린다. 석 잔째는 부도덕하게 되고, 넉 잔째에서는 자멸(自滅)한다. -탈무드

댓글 ( 4)

댓글 남기기

작성