Experiment No.2 Aim:: To Develop An Application That Draws Basic Graphical Primitives On The Screen
Experiment No.2 Aim:: To Develop An Application That Draws Basic Graphical Primitives On The Screen
Experiment No.2
Aim: To develop an application that draws basic graphical primitives on the screen.
Problem statement: Develop an android application to draw line, circle, rectangle and square on
screen using ImageView, Canvas class and Paint class.
Theory:
ImageView:
• ImageView class is used to display any kind of image resource in the android application
either it can be android.graphics.Bitmap or android.graphics.drawable.Drawable.
• ImageView is also used to control the size and movement of an image.
Code:
//Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
//MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
@Override
CST411: Mobile Application Development Lab Class: TY [B] Roll :38
Course Coordinator: Mrs. Mrunal Deshpande Name: Latika Nandai
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
Paint paint1 = new Paint();
Paint paint2 = new Paint();
Paint paint3 = new Paint();
paint.setColor(Color.RED);
paint1.setColor(Color.BLACK);
paint2.setColor(Color.YELLOW);
paint3.setColor(Color.BLUE);
paint.setTextSize(50);
Output:
CST411: Mobile Application Development Lab Class: TY [B] Roll :38
Course Coordinator: Mrs. Mrunal Deshpande Name: Latika Nandai