You are on page 1of 2

PRACTICAL NO – 23

Name: Sarthak Bagul Class: TYCM-Mac

<?xml version="1.0" encoding="utf-8"?>


<AbsoluteLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Camera Application"
android:layout_y="30dp"
android:layout_x="90dp"/>
<ImageView
android:id="@+id/iv"
android:layout_width="300dp"
android:layout_height="318dp"
android:layout_x="62dp"
android:layout_y="103dp"
android:background="#FFEB3B" />
<Button
android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="139dp"
android:layout_y="488dp"
android:background="@color/material_dynamic_neutral0"
android:text="Click to Capture" />
</AbsoluteLayout>

package com.example.pr23;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
ImageView iv;
Button b;
@SuppressLint("MissingInflatedId")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView) findViewById(R.id.iv);
b=(Button) findViewById(R.id.b);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent opencamera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(opencamera,04);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,@Nullable Intent date){
super.onActivityResult(requestCode,resultCode,date);
if(requestCode==04)
{
if(resultCode==RESULT_OK)
{
Bitmap photo=(Bitmap) date.getExtras().get("data");
iv.setImageBitmap(photo);
}
}
}
}
Output:

You might also like