How to display picture in imageview photo taken by camera in android

后端 未结 3 1419
走了就别回头了
走了就别回头了 2021-01-07 05:30

can anybody tell How to display picture in imageview photo taken by using front camera in android can anybody provide code

Thanks

3条回答
  •  没有蜡笔的小新
    2021-01-07 05:44

    here is the code try it

    here is my xml file

    
    
        

    here is the activity code

    Button btn;
    int CAMERA_PIC_REQUEST = 0;
    ImageView imgView;
    
    imgView = (ImageView) findViewById(R.id.img_preview);
    
        btn = (Button) findViewById(R.id.btn);
        btn.setCompoundDrawables(null, getResources().getDrawable(R.drawable.icon), null, null);
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent camera_intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
                        }
          });
    

    here is the onActivityResult

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode){
        case CAMERA_PIC_REQUEST:
            if(resultCode==RESULT_OK){
               Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
               imgView.setImageBitmap(thumbnail);
                }
        }
    }
    

提交回复
热议问题