【发布时间】:2020-01-14 13:51:37
【问题描述】:
在我的项目中,我使用圆形图像视图来显示从手机图库中获取的图像,然后将图像设置为图像视图,直到这里一切正常。
但问题是当我从一个片段到另一个片段进行交易时,图像会被删除。
所以我需要一个代码 sn-p 来帮助我从图库中挑选图像并裁剪它,然后将图像永久显示在图像视图中。
PS:此图像也已上传到 Fire Base 存储。所以请帮助我如何解决这个问题
用于图像提取
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK){
Uri imageUri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), imageUri);
profileImage.setImageBitmap(bitmap);
}catch (IOException e){
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
用于图像选择
profileImage = view.findViewById(R.id.profile_image);
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gallery = new Intent();
gallery.setType("image/*");
gallery.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(gallery,"Select Profile Image"), PICK_IMAGE);
}
});
【问题讨论】:
标签: android-studio sharedpreferences android-imageview