如何获取前置摄像头拍摄的图像路径

时间:2017-10-04 12:03:20

标签: java android android-camera android-camera-intent

我只想获取前置摄像头拍摄的图像。

是否有任何意图或媒体功能可以为我提供由前置摄像头(自拍相机)拍摄的所有图像路径

提前致谢。

2 个答案:

答案 0 :(得分:1)

  

是否有任何意图或媒体功能可以为我提供由前置摄像头(自拍相机)拍摄的所有图像路径

没有

答案 1 :(得分:1)

虽然没有直接的方法,但您可以获取exif文件夹中每张图片的DCIM元数据,然后检查TAG_MODEL(或其他任何内容)特征)匹配您的前置摄像头的规格。

从图像文件(source)获取exif元数据的示例代码:

public class AndroidExif extends Activity {

 TextView myTextView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        myTextView = (TextView)findViewById(R.id.textview);

        //change with the filename & location of your photo file
        String filename = "/sdcard/DSC_3509.JPG";
        try {
   ExifInterface exif = new ExifInterface(filename);
   ShowExif(exif);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   Toast.makeText(this, "Error!", 
     Toast.LENGTH_LONG).show();
  }
    }

    private void ShowExif(ExifInterface exif)
    {
     String myAttribute="Exif information ---\n";
     myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif);
     myAttribute += getTagString(ExifInterface.TAG_FLASH, exif);
     myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE, exif);
     myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE_REF, exif);
     myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif);
     myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE_REF, exif);
     myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH, exif);
     myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH, exif);
     myAttribute += getTagString(ExifInterface.TAG_MAKE, exif);
     myAttribute += getTagString(ExifInterface.TAG_MODEL, exif);
     myAttribute += getTagString(ExifInterface.TAG_ORIENTATION, exif);
     myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE, exif);
     myTextView.setText(myAttribute);
    }

    private String getTagString(String tag, ExifInterface exif)
    {
     return(tag + " : " + exif.getAttribute(tag) + "\n");
    }
}