更改拍摄图像的路径

时间:2013-07-07 12:26:39

标签: android image assets

我正在尝试使用assets资源文件夹中的图像执行Horizo​​ntalScrollview。我正在使用一个从外部存储获取图像的示例,我不知道如何更改资源文件夹的路径。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myGallery = (LinearLayout)findViewById(R.id.mygallery);

    String ExternalStorageDirectoryPath = Environment
      .getExternalStorageDirectory()
      .getAbsolutePath();

    String targetPath = ExternalStorageDirectoryPath + "/test/";

    Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
    File targetDirector = new File(targetPath);

    File[] files = targetDirector.listFiles();
    for (File file : files){
         myGallery.addView(insertPhoto(file.getAbsolutePath()));
    }    
}

1 个答案:

答案 0 :(得分:0)

阅读资产非常简单:

单张照片:

AssetManager assetManager = getResources().getAssets();
InputStream is = assetManager.open("photo.jpeg");

照片列表:

AssetManager  assetManager = getResources().getAssets();
String[] files =  assetManager.list("");
for(String f: files){
    File photo = new File(f); //or
    InputStream is = assetManager.open(f);
    //do something with the photo

}