2017-10-04 265 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"); 
    } 
} 
相關問題