1
我有一個圖像在SD card
我想從SD card
拍攝圖像並設置在ImageView
。請幫助我們我已經嘗試了下面的代碼。將SD卡圖像設置爲ImageView?
我的代碼:
sendImageFromFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri=null;
ArrayList<Uri> arrayList=new ArrayList<Uri>();
ImageView imageView= (ImageView) findViewById(R.id.imageView);
File pictues= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String[] listOfPictures=pictues.list();
for(String s:listOfPictures){
uri=Uri.parse("file://"+ pictues.toString() +"/"+s);
arrayList.add(uri);
}
InputStream inputStream = null;
FileOutputStream fileOutputStream=null;
Bitmap bmp;
try {
inputStream = getContentResolver().openInputStream(arrayList.get(0));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
bmp = BitmapFactory.decodeStream(bufferedInputStream);
imageView.setImageBitmap(bmp);
}
是什麼?PictureFile的 –
查看已更新的答案與您的圖片路徑的文件。 –
thaks bro它的工作 –