我寫這段代碼和我的代碼從庫中選擇一張圖片並從中獲取數據但我不知道如何從Inputstrem或數據獲取圖像地址並將其存儲?如何從android庫中獲取地址
public void loadPic()
{
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1)
{
try {
Uri selectedImage=data.getData();
InputStream inputStream = getContentResolver().openInputStream(selectedImage);
listItems.add(inputStream.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
爲什麼你需要從圖庫中選擇圖像的路徑?你可以用'onActivityResult'回調中的Intent得到的'InputStream'完成你想做的任何事情。 –
使用BitmapFactory獲取位圖,一致 bmp = BitmapFactory.decodeStream(inputStream); – prGD
真的!我可以將它複製到另一個地方嗎 – Amir133