Capture image with camera in android and save with a custom name

前端 未结 3 541
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 10:36

i have create an android application that will capture picture and save in sdcard folder,now i want to save the image with a custom name.

import java.io.Byte         


        
相关标签:
3条回答
  • 2021-01-07 10:37

    You need to put fileName as Intent Extras -

    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, "android.jpg");
    
    0 讨论(0)
  • 2021-01-07 10:55

    this article maybe useful, try it.

    & this as well, the only different that he used the date as a default name. change it.

    It usually works :)

    0 讨论(0)
  • 2021-01-07 11:01
    File outFile = new File(Environment.getExternalStorageDirectory(), "myname.jpeg");
    FileOutputStream fos = new FileOutputStream(outFile);
    photo.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
    fos.flush();
    fos.close();
    

    you would also need to add Permission in Android Manifest.

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    the snippet will save the content of photo inside /sdcard with the name "myname.jpeg"

    0 讨论(0)
提交回复
热议问题