我可以从firebase存储中下载我的图像uri。点击按钮我想将图像下载到手机上。我已经编写了完整的代码,但点击它没有任何反应。
我在getIntent()中有图像uri.getStringExtra(" Image")
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// new DownloadImage().execute(getIntent().getStringExtra("Image"));
Toast.makeText(getApplicationContext(), "Hi", Toast.LENGTH_SHORT).show();
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
Bitmap bitmap = Glide.with(getApplicationContext()).load(getIntent().getStringExtra("Image")).asBitmap().into(100, 100).get();
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
答案 0 :(得分:0)
考虑到您的getIntent().getStringExtra("Image")
有图片Uri,您可以使用:
Glide
.with(getApplicationContext())
.load(getIntent().getStringExtra("Image"))
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
//Now save this resource
}
});
注意:在这种情况下,必须提供确切的尺寸(低于1的任何内容都不被接受)