Welcome to EasyCoding with AmmaraSubscribe My Coding Channel:https://www.youtube.com/channel/UC8UsfNYmbKiRJvI9ZhhApEw?view_as=subscriber
Subscribe my personal YouTube Channel:https://www.youtube.com/channel/UCa93R2oNQMuX0fOKa9eV4zg?view_as=subscriber
Let's Start Watch My Complete Camera Video:
https://www.youtube.com/watch?v=WL9okRCtwG8
Watch My Complete Camera Video:
https://www.youtube.com/watch?v=WL9okRCtwG8
Description:
In this video, I am going to show to how to take image in your application using camera. First I take image using camera and then show in imageview. So Let's Start.1) Paste Code to Manifests.
2) Paste Code to MainActivity.java.
public class MainActivity extends Activity {
static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=findViewById(R.id.imageView);
}
public void OpenCamera(View view){
dispatchTakePictureIntent();
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageView.setImageURI(fileUri);
}
}
}
3) Paste Code to Main Activity.xml.
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">