0
            Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            takePicture.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            startActivityForResult(takePicture,0);



protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
  //  Bitmap bitmap =(Bitmap)data.getExtras().get("Data");
   // imageView.setImageBitmap(bitmap);

    FaceDetector detector;
    ImageView myImageView = (ImageView) findViewById(R.id.ivImage);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inMutable=true;

    fileUri  = getOutputMediaFileUri(FileColumns.MEDIA_TYPE_IMAGE);

    final  Bitmap myBitmap = BitmapFactory.decodeFile(fileUri.toString(),options);


 // Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.me);


    Paint myRectPaint = new Paint();
    myRectPaint.setStrokeWidth(5);
   myRectPaint.setColor(Color.RED);
   myRectPaint.setStyle(Paint.Style.STROKE);



   Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);
    Canvas tempCanvas = new Canvas(tempBitmap);
    tempCanvas.drawBitmap(myBitmap, 0, 0, null);


   FaceDetector faceDetector = new  FaceDetector.Builder(getApplicationContext()).setTrackingEnabled(false).build();


   Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
   SparseArray<com.google.android.gms.vision.face.Face> faces = faceDetector.detect(frame);
   if(!faceDetector.isOperational())
   {
        new AlertDialog.Builder(this).setMessage("Face Detector :(").show();
        return;
   }
    for(int i=0; i<faces.size(); i++)
    {
       Face thisFace = faces.valueAt(i);
       float x1 = thisFace.getPosition().x;
       float y1 = thisFace.getPosition().y;
       float x2 = x1 + thisFace.getWidth();
       float y2 = y1 + thisFace.getHeight();
       tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint);
    }

   myImageView.setImageDrawable(new BitmapDrawable(getResources(),tempBitmap));
}

error

at this point

12-04 19:54:41.419 14215-14215/com.example.user.demo E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: file:/storage/emulated/0/Pictures/IMAGE_DIRECTORY_NAME/IMG_20171204_195441.jpg: open failed: ENOENT (No such file or directory) 12-04 19:54:41.462 14215-14215/com.example.user.demo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.user.demo, PID: 14215

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/139760 typ=image/jpeg (has extras) }} to activity {com.example.user.demo/com.example.user.demo.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at com.example.user.demo.MainActivity.onActivityResult ->>>. Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);

William-H-M
  • 1,050
  • 1
  • 13
  • 19
Bhavika
  • 1
  • 1
  • 1
    Please expleain a little bit more what you're triying just code won't help anybody, see [How to Ask](https://stackoverflow.com/help/how-to-ask) – William-H-M Dec 04 '17 at 14:33
  • i m trying to perform "taking a picture from camera and perform face detection on it...using mobile vision api.. – Bhavika Dec 05 '17 at 03:57
  • are you sure that you have written the android permisions for write and read file on the storage inside your android manifest? – William-H-M Dec 05 '17 at 12:50
  • @William-H-M ..yes... – Bhavika Dec 05 '17 at 13:02
  • @William-H-M.... – Bhavika Dec 05 '17 at 13:03
  • First Error:----12-05 18:35:48.757 14136-14136/com.example.user.demo E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/IMAGE_DIRECTORY_NAME/IMG_20171205_183548.jpg: open failed: ENOENT (No such file or directory) – Bhavika Dec 05 '17 at 13:11
  • @William-H-M.......And Second Error..:-/AndroidRuntime: FATAL EXCEPTION: main Process:ResultInfo{who=null, request=0, result=-1, data=Intentct=inlinatadat=content://media/external/images/media/139998 typ=image/jpeg (has extras) }} to activity com.example.user.demo/com.example.user.demo.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at ->>Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565); – Bhavika Dec 05 '17 at 13:14
  • please don't add code to comments [edit](https://stackoverflow.com/posts/47635516/edit) your question and then add it there – William-H-M Dec 05 '17 at 13:28
  • ok..now what i do? – Bhavika Dec 05 '17 at 13:33
  • See [this](https://stackoverflow.com/questions/25467007/unable-to-decode-stream-java-io-filenotfoundexception-storage-emulated-0-open-f) and [this](https://stackoverflow.com/questions/42571558/bitmapfactory-unable-to-decode-stream-java-io-filenotfoundexception) and [this one](https://stackoverflow.com/questions/33410240/unable-to-detect-different-images-for-face-detection-mobile-vision-api) they all are related to error accessing files that is the problem you're currently having. – William-H-M Dec 05 '17 at 13:40
  • @William-H-M actually my code work for that image which i added directyy in code from drawable folder.... "Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.me);" but i want to do.."first click image from camera and then face detection on that image" – Bhavika Dec 06 '17 at 04:24

0 Answers0