ANDROID IMAGE CAPTURE FROM CAMERA AND DISPLAY TO <IMAGEVIEW />
STEP1
CREATE activity_main.xml with following code
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ImageFromCameraAndGallary" />
<ImageView
android:id="@+id/imgview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<Button
android:id="@+id/buttonClickImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imgview"
android:text="Click Image"
/>
STEP2
CREATE MainActivity.java with following code
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
public ImageView image;
public Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.imgview);
button = (Button) findViewById(R.id.buttonClickImage);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent camaeraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camaeraIntent, CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
image.setImageBitmap(photo);
}
}
}
STEP3
FINALLY give premission to use camera to our android app by giving permission in android.manifest.xml
<uses-feature android:name="android.hardware.camera"></uses-feature>
IT works fine...
STEP1
CREATE activity_main.xml with following code
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ImageFromCameraAndGallary" />
<ImageView
android:id="@+id/imgview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_below="@+id/text"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<Button
android:id="@+id/buttonClickImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imgview"
android:text="Click Image"
/>
STEP2
CREATE MainActivity.java with following code
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
public ImageView image;
public Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.imgview);
button = (Button) findViewById(R.id.buttonClickImage);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent camaeraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camaeraIntent, CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
image.setImageBitmap(photo);
}
}
}
STEP3
FINALLY give premission to use camera to our android app by giving permission in android.manifest.xml
<uses-feature android:name="android.hardware.camera"></uses-feature>
IT works fine...
No comments:
Post a Comment