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

前端 未结 3 538
被撕碎了的回忆
被撕碎了的回忆 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 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.

    
    

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

提交回复
热议问题