0

Je lis une image vectorielle à partir d'une ressource XML et l'affiche dans un ImageView. C'est bon. Maintenant, je dois passer l'image à un Intention avec intention.putExtra. Question: Comment puis-je convertir le vecteur XML en bitmap ou obtenir l'image à partir d'ImageView? J'ai essayé .getDrawingCache(), .getDrawable, getImageMatrix, etc, mais cela ne fonctionne pas.Comment faire pour récupérer un bitmap à partir d'une image vectorielle dans une ressource XML

Essayé de cette façon:

String path = MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(), 
      imgPrevisao.getDrawingCache(), 
      "Minha previsão",null); 

    Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
    sharingIntent.setType("image/*"); 
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)) ; 
    getApplicationContext().startActivity(Intent.createChooser(sharingIntent, "Share with")); 

Et cette façon:

Intent intent = new Intent(Intent.ACTION_SEND); 

    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    intent.putExtra(Intent.EXTRA_TEXT, textoPrevisao); 
    intent.putExtra(Intent.EXTRA_STREAM, imgPrevisao.getDrawingCache()); 
    intent.setType("image/*"); 
    startActivity(intent); 

TIA,

André Corrêa

+0

Quelque chose comme ça devrait fonctionner. Opération assez standard pour récupérer un bitmap à partir d'une vue d'image. – greenapps

+0

Cette intention devrait être traitée dans votre application? – j2ko

+0

greenapps, désolé, quelque chose comme quoi? Je suis nouveau avec Android en développement. –

Répondre

0

Une des façons est d'utiliser MediaStore:

public static Uri getImageUri(Context context, Bitmap bmp) { 
    String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), , "share_title",bmp ,null); 
    return Uri.parse(path); 
} 

et que:

public static void shareImageViewContent(ImageView view) { 
    Bitmap bitmap = ((BitmapDrawable)view.getDrawable()).getBitmap(); 
    Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
    sharingIntent.setType("image/jpeg"); 
    sharingIntent.putExtra(Intent.EXTRA_STREAM, getImageUri(bitmap)) ; 
    context.startActivity(Intent.createChooser(sharingIntent, "Share with")); 
} 

Un peu plus compliquée solution consiste à utiliser FileProvider Crédits: link, link, link

+0

Merci j2ko, je vais essayer ça. Je n'ai pas assez de réputation pour remettre en question votre réponse, désolé. –

+0

@ AndréAranha np, je suis heureux d'aider. Mais je suppose que vous pourriez marquer ma solution comme réponse – j2ko

+0

cela ne fonctionne pas. J'essaye toujours. Je posterai ce que j'ai essayé. –