Get Error when capture image

前端 未结 2 1898
傲寒
傲寒 2021-01-29 03:55

I want to capture image using camera and want image path.

I try following code but I get Error. (I follow this link Get Path of image from ACTION_IMAGE_CAPTURE Intent)

相关标签:
2条回答
  • 2021-01-29 04:14
    if (resultCode != RESULT_CANCELED) {
        if (requestCode == CAMERA_REQUEST) {
    
         String[] projection = { MediaStore.Images.Media.DATA };
          Cursor cursor = managedQuery(mCapturedImageURI, projection,                   null, null, null);
                    int column_index_data = cursor
                            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                    cursor.moveToFirst();
                    String capturedImageFilePath = cursor
                            .getString(column_index_data);
    
                    Toast.makeText(getApplicationContext(),
                            capturedImageFilePath.toString(), Toast.LENGTH_LONG)
                            .show();
    
                }
            }
    

    you try this one i think they will help you..

    0 讨论(0)
  • 2021-01-29 04:28

    Finally I got Ans.

    photoButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
    
               File file = new File(Environment.getExternalStorageDirectory()+"/test1.jpg");
                Uri outputFileUri = Uri.fromFile(file);
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(intent, 0);
    
            }
        });
    
    
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            Log.i("MakeMachine", "requestCode:"+requestCode + ",resultCode: " + resultCode);
    
                            File file = new File(Environment.getExternalStorageDirectory()+"/test1.jpg");
                            if(file.exists()){
                                BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inSampleSize = 4;
                                picFileName=Environment.getExternalStorageDirectory()+"/test.jpg";
                                Toast.makeText(getApplicationContext(), picFileName, Toast.LENGTH_LONG).show();
                                Bitmap bitmap = BitmapFactory.decodeFile(picFileName, options);
                                imageView.setImageBitmap(bitmap);
                                //imageView.setVisibility(View.VISIBLE);
                            }
    
    
        }
    
    0 讨论(0)
提交回复
热议问题