【问题标题】:How to get front camera captured images path [duplicate]如何获取前置摄像头捕获的图像路径[重复]
【发布时间】:2018-03-15 19:40:58
【问题描述】:

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

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

提前致谢。

【问题讨论】:

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


【解决方案1】:

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

没有。

【讨论】:

  • 好的,感谢您的信息。
【解决方案2】:

虽然没有直接的方法可以做到这一点,但您可以获取DCIM 文件夹中每张图片的exif 元数据,然后检查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");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多