How to pass a String to an imageview

0

I have a big question, I moved an image from one screen to another and I captured your URL , however I need to transform it to Bitmap , and display it in a < in> ImageView .

Follow my code:

public class ComentarActivity extends AppCompatActivity {

    private EditText comentario;
    private Button botaoSalvar;
    private ImageView fotoSelecionada;
    private String obID;
    private ViewPager viewPager;
    private TextView texto;
    Context context;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comentar);

        comentario = (EditText) findViewById(R.id.text_comentario);
        botaoSalvar = (Button) findViewById(R.id.button_salvar);
        fotoSelecionada = (ImageView) findViewById(R.id.imageView2);



        //passando uma foto da galeria para a imageviewe


        Intent i = getIntent();
        obID = i.getStringExtra("imagem");

        byte[] decodedString = Base64.decode(obID, Base64.DEFAULT);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        Drawable foto = new BitmapDrawable(getResources(), decodedByte);
        fotoSelecionada.setImageBitmap(foto);

Any suggestions ??

    
asked by anonymous 25.04.2018 / 04:42

1 answer

0

You can use the Picasso library to load the image into ImageView.

Import the library:

  

compile 'com.squareup.picasso: picasso: 2.5.2'

If it is in your Activity for example, do so set the path in ActivityResult after selecting the gallery photo:

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK) {

     Uri selectedPictureUri = data.getData();
     String picturePath = getRealPathFromURI(selectedImageUri);
     loadIntoImageView(picturePath);
}

public void loadIntoImageView(String path){
     Picasso.with(context)
                    .load(path)
                    .into(imageView);
}
    
27.04.2018 / 20:18