"Jai Saraswati Maa"
Hi ... Dear All ..Today I am uploading a superb example of Taking photo using camera App .
Image will be shown at your specified image view
Please check.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
Please Like us & put your valuable suggestions in comment box.
***** check on physical device
Suggestion - Add Features and permissions in manifest file like
Hi ... Dear All ..Today I am uploading a superb example of Taking photo using camera App .
Image will be shown at your specified image view
Please check.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
Please Like us & put your valuable suggestions in comment box.
***** check on physical device
Suggestion - Add Features and permissions in manifest file like
<uses-feature android:name="android.hardware.camera2" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
A. Add a Button and image view in layout file like
our xml code is
<?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"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.exam.ravi.cameraex1.ThirdAct"> <Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Camera"android:id="@+id/button3"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="48dp"android:onClick="clickMe"/> <ImageView android:layout_width="300dp"android:layout_height="400dp"android:id="@+id/imageView2"android:layout_below="@+id/button3"android:layout_centerHorizontal="true"android:layout_marginTop="44dp" /> </RelativeLayout>B. Java Filepackage com.exam.ravi.cameraex1; 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.View; import android.widget.ImageView; public class ThirdAct extends AppCompatActivity { ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); imageView = (ImageView) findViewById(R.id.imageView2); } public void clickMe(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0); } @Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { Bitmap bp = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(bp); } }
No comments:
Post a Comment