Je veux utiliser Glide pour enregistrer une image bitmap dans un fichier et ensuite partager l'image avec un bouton Partager. Je l'ai utilisé un code que j'ai trouvé dans la documentation, comme ceci:Glisser enregistrer l'image dans le fichier - Bitmap recyclé
Glide.with(getApplicationContext())
.load(imageUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap b, GlideAnimation<? super Bitmap> glideAnimation) {
File file = getExternalFilesDir(null);
try {
URI uri = new URI(imageUrl);
String path = uri.getPath();
String nameOfFile = file + "/" + path.substring(path.lastIndexOf('/') + 1);
OutputStream os = new FileOutputStream(nameOfFile);
b.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.flush();
os.close();
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + nameOfFile));
share.setType("image/*");
startActivity(Intent.createChooser(share, getResources().getString(R.string.action_share)));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
});
La chose est que au hasard, les accidents d'application, car le Bitmap b est recyclé avant compriment. Comment puis-je éviter ça? Y a-t-il un meilleur moyen?