0

In Android studio , in my app the image is not getting replaced with the bitmap I create,the path is correct but the ic_action_android is not getting replaced with my fresh captured image. In OnCreate:

btOpen.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {
                //Open Camera
                // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if(cameraIntent.resolveActivity(getPackageManager())!=null)
                {
                    File imageFile= null;
                    try{
                        imageFile = getImageFile();
                    }catch(IOException e){
                        Toast.makeText(getApplicationContext(), "get image file failed", Toast.LENGTH_SHORT).show();
                        e.printStackTrace();
                    }
                    if(imageFile != null)
                    {
                        Uri imageUri= FileProvider.getUriForFile(MainActivity.this,"com.example.android.provider",imageFile);
                        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
                        startActivityForResult(cameraIntent,IMAGE_REQUEST);
                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(), "Imagefile is null", Toast.LENGTH_SHORT).show();
                    }

                }
                //startActivityForResult(intent,100);
            }
        });



  private File getImageFile()throws IOException
    {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageName="jpg_"+timeStamp+"_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File imageFile = File.createTempFile(imageName,".jpg",storageDir);
        currentImagePath= imageFile.getAbsolutePath();
        return imageFile;
    }

The on Activity result:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    ImageView imageView= new ImageView(MainActivity.this);
    imageView.setImageResource(R.drawable.ic_action_android);
    addView(imageView,1000,1000);
    Log.i(TAG, "The image path is " + currentImagePath);
    final Bitmap mBitmap= BitmapFactory.decodeFile(getIntent().getStringExtra(currentImagePath));
    if (requestCode == 100) {
        //Get Capture Image
       // Bitmap captureImage = (Bitmap) data.getExtras().get("data");
        //Set Captue Image to ImageView
        imageView.setImageBitmap(mBitmap);
       // imageView.setImageBitmap(captureImage);

    }

imageView.setImageBitmap(mBitmap); this line is not working so to say.

Bruno
  • 3,872
  • 4
  • 20
  • 37
  • https://stackoverflow.com/questions/62653207/android-10-bitmapfactory-decodefileimagefilepath-return-null – blackapps Jun 30 '20 at 11:00
  • `imageView.setImageBitmap(mBitmap); this line is not working so to say.` No. The line before delivers a null bitmap. But then the link i provided will do too. – blackapps Jun 30 '20 at 11:02
  • decodeFile(getIntent().getStringExtra(currentImagePath)); instead of this I had to do decodeFile(currentImagePath) – Mandar Ancharwadkar Jun 30 '20 at 11:02

0 Answers0