0% found this document useful (0 votes)
15 views22 pages

Maad

Uploaded by

prajwalcharthad6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views22 pages

Maad

Uploaded by

prajwalcharthad6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

-23=..

‘}k

/.

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

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button android:id="@+id/camera_button"

android:layout_width="100dp"

android:layout_height="50dp"

android:layout_marginStart="150dp"

android:text="Camera" />

<ImageView android:id="@+id/click_image"

android:layout_width="350dp"

android:layout_height="450dp"

android:layout_marginStart="30dp"

android:layout_marginTop="70dp"

android:layout_marginBottom="10dp" />

<TextView android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Prajwal Charthad"

android:textStyle="bold"/>

</RelativeLayout>

Java

package com.example.myapplication4;

import android.content.Intent;

import android.graphics.Bitmap;

import android.os.Bundle;
import android.provider.MediaStore;

import android.widget.Button;

import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private static final int pic_id = 123;

Button camera_open_id;

ImageView click_image_id;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

camera_open_id = findViewById(R.id.camera_button);

click_image_id = findViewById(R.id.click_image);

camera_open_id.setOnClickListener(v -> {

Intent camera_intent = new

Intent(MediaStore.ACTION_IMAGE_CAPTURE);

// Start the activity with camera_intent, and request pic id

startActivityForResult(camera_intent, pic_id); });

// This method will help to retrieve the image

protected void onActivityResult(int requestCode, int resultCode, Intent data)

super.onActivityResult(requestCode, resultCode, data);

// Match the request 'pic id with requestCode

if (requestCode == pic_id) {

// BitMap is data structure of image file which store the image in

Bitmap photo = (Bitmap) data.getExtras().get("data");

// Set the image in imageview for display

click_image_id.setImageBitmap(photo);

}
}

You might also like