Paint Style( Graphics)

Paint style এর মাঝে তিন ধরনের স্টাইল উল্লেখ যোগ্য
LinearGradient
RadialGradient
SweepGradient
তা ছাড়া Paint Style setStyle() use করেও স্টাইল চেঞ্জ করা যায় ।
Paint linePaint = new Paint();
linePaint.setStyle(Paint.Style.STROKE);
এর মাধ্যমে স্টোক দেওয়া যায়।


paintSyle.java

package com.example.graphics2d;

import android.app.Activity;
import android.os.Bundle;

public class paintStyle extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new style(this));
}

}

style.java
package com.example.graphics2d;

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

public class style extends View {

public style(Context context) {
super(context);
// TODO Auto-generated constructor stub

}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);

canvas.drawColor(Color.BLACK);

Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);-----এখানে স্টোক দেওয়া হয়েছে

Typeface face=Typeface.createFromAsset(getContext().getAssets(), "chess1.ttf");

paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setTypeface(face);

canvas.drawText("WwQqRr ",20,20, paint);
canvas.drawText("WwQqRr ",20,40, paint);
canvas.drawText("WwQqRr ",20,120, paint);
canvas.drawText("WwQqRr ",20,150, paint);

paint.setColor(Color.RED);
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);

}

}four

customise Text

আগের পোস্টটি এখবার দখে আসলে বঝতে সুবিধা হবে।
এবার আমরা custom text লেখা দেখব । কিভাবে custom font ব্যাবহার করা যায়। দেখব কিভাবে chess এর symbol text হিসেবে ব্যাবহার করা যায় ।প্রথমে আমরা এখান থেকে ডাউন লোড করে নিই ।তার পর নিচের মত কোড লেখি —- after downloading the font we have to paste it onto asset folder then it ok .

When you type a: You get a:
Q A black queen on a white square
q A white queen on a white square
W A black queen on a black square
w A white queen on a black square
R A black rook on a white square
r A white rook on a white square
T A black rook on a black square
t A white rook on a black square
N A black knight on a white square
n A white knight on a white square
M A black knight on a black square
m A white knight on a black square
B A black bishop on a white square
b A white bishop on a white square
V A black bishop on a black square
v A white bishop on a black square
K A black king on a white square
k A white king on a white square
L A black king on a black square
l A white king on a black square
P A black pawn on a white square
p A white pawn on a white square
O A black pawn on a black square
o A white pawn on a black square
/ An empty black square
A space An empty white square
1 An upper border side
2 An right border side
3 An left border side
4 An lower border side
5 An upper left corner of the border
6 An upper right corner of the border
7 An lower left corner of the border
8 An lower right corner of the border

package com.example.graphics2d;

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

public class Circle2D extends View {

public Circle2D(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);

canvas.drawColor(Color.BLACK);

Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);

//Typeface face=Typeface.create(Typeface.MONOSPACE, Typeface.BOLD_ITALIC);
Typeface face=Typeface.createFromAsset(getContext().getAssets(), "chess1.ttf");//path দখিয়ে দিলাম।

paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setTypeface(face);

canvas.drawText("WwQqRr ",20,20, paint);
canvas.drawText("WwQqRr ",20,40, paint);
canvas.drawText("WwQqRr ",20,120, paint);
canvas.drawText("WwQqRr ",20,150, paint);

paint.setColor(Color.RED);
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);

}

}
tree

canvas এ text দেওয়া

এবার আমরা জানব canvas এ কিভাবে text add করা যায়। তার আগে এর আগের পোস্ট টি দেখে আসা ভাল-circle draw

package com.example.graphics2d;

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

public class Circle2D extends View {

public Circle2D(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);

canvas.drawColor(Color.BLACK);

সবার আগে flag add করে নিতে হবে
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);


paint.setColor(Color.CYAN);---কালার এড করলাম
paint.setTextSize(20);----্টেস্ক সাইজ় এড করলাম
paint.setTypeface(null);----টাইপফেস নাল রাখলাম । এখানে বলে রখা দরকার এটি ডিফল্ process . it ser sans-sarif as a font and normal mode if we change this we have to add [Typeface face=Typeface.create(Typeface.MONOSPACE, Typeface.BOLD_ITALIC)] and have to set face replaced by null in paint.setTypeface() .

paint.setFlags(Paint.UNDERLINE_TEXT_FLAG);-----to underLine the text
canvas.drawText("It is a Circle",20,20, paint);----it is the main form to add text . canvas.drawText() has four argument one-text two-width three--height forth-- Paint that we set before


paint.setColor(Color.RED);
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);

}

}

one

এবার Typeface face=Typeface.create(Typeface.MONOSPACE, Typeface.BOLD_ITALIC); সেট করলে text এমন দেখাবে

package com.example.graphics2d;

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

public class Circle2D extends View {

public Circle2D(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);

canvas.drawColor(Color.BLACK);

Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);

Typeface face=Typeface.create(Typeface.MONOSPACE, Typeface.BOLD_ITALIC);---for this we set our custom Typeface

paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setTypeface(face);
paint.setFlags(Paint.UNDERLINE_TEXT_FLAG);
canvas.drawText("It is a Circle",20,20, paint);
paint.setColor(Color.RED);
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);

}

}

two

circle অংকন

আমরা এখন দেখব কিভাবে android এ গ্রাফিক্স নিয়ে কাজ করা যায় । নিচে একটি circle draw করেছি যার background Black


Circle.class

package com.example.graphics2d;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class Circle extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Circle2D(this));// circle2D class কল করলাম।

}

}

Circle2D.class


package com.example.graphics2d;

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

public class Circle2D extends View {

public Circle2D(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {//onDraw method নিলাম ।এটি মুলত graphics draw করার জন্যuse kora হয়
// TODO Auto-generated method stub
super.onDraw(canvas);

canvas.drawColor(Color.GREEN);//background color is green

Paint paint=new Paint();//to paint

paint.setColor(Color.RED);//color set as red
canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);
[canvas.drawCircle(canvas.getWidth()/2,canvas.getHeight()/2, canvas.getWidth()/3, paint);
canvas.getWidth()/2------width কোথায় হবে তা নির্ধারন করে দিলাম। এর মানে হল টোটাল ওয়াইডের –হাফ পজিশানে সেট করলাম
canvas.getHeight()/2--------একই ভাবে হাইট সেট করলাম
canvas.getWidth()/3--------- এটি গুরুত্তপূর্ন । এটি বোঝায় আয়তন কত হবে ।আমরা টোটাল হাইটের এক-ত্রিতিয়াং করলাম
paint-----পেন্ট ক্লাসের অব্জেক্ট]

}

}

Capture