我的图像来自片段onActivityresult
调用自定义图库
Custom_Gallery custom_gallery=new Custom_Gallery();
custom_gallery.setTargetFragment(this,301);
getFragmentManager().beginTransaction().replace(R.id.FragmentMain,custom_gallery).addToBackStack(null).commit();
将结果发送回自定义图库中的片段
bundle.putStringArrayList("Media",media);
Intent intent = new Intent();
intent.putExtras(bundle);
getTargetFragment().onActivityResult(getTargetRequestCode(),getActivity().RESULT_OK,intent);
FragmentManager fragmentManager=getFragmentManager();
fragmentManager.popBackStack();
在onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==301 && resultCode==getActivity().RESULT_OK){
List<String> image=data.getStringArrayListExtra("Media");
Log.d(TAG,"Image "+image.get(0));
String img=image.get(0);
//File uploadedImage = new File(image.get(0));
/*Bitmap myImage=BitmapFactory.decodeFile(image.get(0));
uploadImage.setImageBitmap(myImage);*/
Glide.with(getActivity()).load(img)
.apply(new RequestOptions()
.skipMemoryCache(true)
.error(R.drawable.add_fav)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.NONE))
.into(uploadImage);
uploadButton.setEnabled(true);
functions=new App_Functions(getActivity());
Bitmap bitmap = BitmapFactory.decodeFile(image.get(0));
String Base64Image=functions.Convert_To_Base64(bitmap);
//Log.d(TAG,"Base 64 "+Base64Image);
}
}
这是我从Fragment onActivityResult
/storage/emulated/0/Download/Media/Images/Ximg1520693707996.jpg
我尝试使用Bitmap的decodefile方法,然后手动设置为Imageview
,但仍然无法工作我认为它的Glide问题,但它甚至没有设置Bitmap。
答案 0 :(得分:0)
android生态系统的生命周期存在问题。 onResume
之后的onActivityResult
调用。我需要在String
获取结果时将图像路径保存在onActivityResult
中,然后在ImageView
的{{1}}中的设置路径上使用它,