0% found this document useful (0 votes)
16 views2 pages

Prac23 1

The document describes a program to capture an image from the camera and display it in an image view. It includes the Android manifest and Java files needed to build the app interface and functionality. The app allows taking a photo using the device camera and then displays the captured image in an image view on the app screen.

Uploaded by

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

Prac23 1

The document describes a program to capture an image from the camera and display it in an image view. It includes the Android manifest and Java files needed to build the app interface and functionality. The app allows taking a photo using the device camera and then displays the captured image in an image view on the app screen.

Uploaded by

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

Practical No: 23

Q.1 write a program to capture an image and display it using image view
AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_margin="16dp"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click the below button to take photo from camera and display it in image view"/>

<Button
android:id="@+id/take_image_from_camera"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:onClick="takeImageFromCamera"
android:layout_height="wrap_content"
android:text="Take Photo From Camera"/>

<ImageView
android:id="@+id/image_from_camera"
android:layout_width="200dp"
android:src="@drawable/image"
android:layout_height="300dp"
android:layout_marginTop="16dp"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="ViralAndroid.com"
android:autoLink="web"
android:textSize="24sp"
android:textStyle="bold"
android:gravity="center|bottom"/>
</LinearLayout>
.java file
package com.viralandroid.androidtutorial;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class CamereCaptureAndDisplayImage extends AppCompatActivity {

private static final int CAMERA_REQUEST = 1888;


ImageView mimageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.capture_image_from_camera_and_display);

mimageView = (ImageView) this.findViewById(R.id.image_from_camera);


Button button = (Button) this.findViewById(R.id.take_image_from_camera);
}

public void takeImageFromCamera(View view) {


Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}

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


if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap mphoto = (Bitmap) data.getExtras().get("data");
mimageView.setImageBitmap(mphoto);
}
}
}

You might also like