我写这段代码和我的代码从库中选择一张图片并从中获取数据但我不知道如何从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