2017-10-04 218 views
-5

我只想获取前置摄像头拍摄的图像。如何获取前置摄像头拍摄的图像路径

是否有这给我的所有图片的路径,其通过前置摄像头(自拍相机)

感谢事先捕获的任何意图或媒体的功能。

+0

我觉得这个链接可以帮助您https://stackoverflow.com/a/4495753/5580210 –

回答

1

是否有这给我的所有图片的路径,其通过前置摄像头(自拍相机)拍摄的任何意向或媒体功能

+0

好了,感谢您的信息。 –

1

虽然并没有一个简单的方法来做到这一点,您可以获取DCIM文件夹中每张图片的exif元数据,然后检查TAG_MODEL(或任何其他特征)是否与您的前置相机的规格相匹配。

示例代码从一个图像文件的元数据exifsource):

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"); 
    } 
} 
相关问题