URI Location to save a photo

前端 未结 3 409
梦毁少年i
梦毁少年i 2021-01-29 07:14

How to create URI Location to save a photo captured by a camera?

I created a intent to start camera to captured photo. I want to pass URI location through the EXTRA_OUTP

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 08:11

    private void SaveImage(Bitmap finalBitmap) {
    
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");    
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-"+ n +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();
    
    } catch (Exception e) {
           e.printStackTrace();
    }
    

    }

提交回复
热议问题