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

Application: Capturing Image Using Mobile Camera and Showing It To User

The document describes an Android application that allows a user to capture an image using a mobile device's camera and display it. The application contains an activity_main.xml layout file with a button and image view, and a MainActivity java class. The button opens the device camera on click, and returns the captured bitmap to display in the image view.

Uploaded by

Kaveri zanzane
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)
56 views2 pages

Application: Capturing Image Using Mobile Camera and Showing It To User

The document describes an Android application that allows a user to capture an image using a mobile device's camera and display it. The application contains an activity_main.xml layout file with a button and image view, and a MainActivity java class. The button opens the device camera on click, and returns the captured bitmap to display in the image view.

Uploaded by

Kaveri zanzane
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/ 2

Application : Capturing Image Using Mobile Camera And Showing It To User.

1.Activity_main.xml

 Design :

 Code :
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="145dp" />

<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp" />
</RelativeLayout>

CAMERA APP 1
1. MainActivity.java
package com.example.d00admin.camera;

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

public class MainActivity extends AppCompatActivity {


Button bt;
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView)findViewById(R.id.imageView);
bt = (Button)findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(in, 0);
}
});
}
protected void onActivityResult(int requestcode, int resultCode, Intent
data){
super.onActivityResult(requestcode, resultCode, data);
Bitmap bp = (Bitmap)data.getExtras().get("data");
iv.setImageBitmap(bp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

CAMERA APP 2

You might also like