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

মন্তব্য করুন

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  পরিবর্তন )

Google photo

You are commenting using your Google account. Log Out /  পরিবর্তন )

Twitter picture

You are commenting using your Twitter account. Log Out /  পরিবর্তন )

Facebook photo

You are commenting using your Facebook account. Log Out /  পরিবর্তন )

Connecting to %s