How to send image loaded volleyball to next operation

I am using volley

to load images and text in listview

in my activity. When I click the line, I pass the image and text to Details . In the detail information, I would like to convey only Image

one more action.

After researching S / O, I found some code that works:

BitmapDrawable bd = (BitmapDrawable) ((NetworkImageView) view.findViewById(R.id.img2))
                    .getDrawable();
            Bitmap bitmapzoom=bd.getBitmap();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bd.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, baos);
            byte[] imgByte = baos.toByteArray();
            Intent intent=new Intent(getApplicationContext(),ZoomImage.class);
            intent.putExtra("image", imgByte);
            startActivity(intent);
        }
    });
      

Run codeHide result


And in the next activity I get it like:

Bundle extras = getIntent().getExtras();
        byte[] b = extras.getByteArray("image");

        Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
        BitmapDrawable background = new BitmapDrawable(bmp);
        findViewById(R.id.img2).setBackgroundDrawable(background);
      

Run codeHide result


However, the image is placed as a background image ... I would like to put an image in my ImageView.

Not as a background like in the code above.

Currently setting the image to the ImageView was not successful. Any suggestions would be greatly appreciated.

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:orientation="vertical"
    tools:context="com.softtech.stevekamau.buyathome.ZoomImage">

    <ImageView
        android:id="@+id/back"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:src="@drawable/back"/>

    <RelativeLayout
        android:id="@+id/root_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000">

        <ImageView
            android:id="@+id/img2"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:scaleType="matrix"
            android:maxHeight="100dp"
            android:maxWidth="50dp" />
    </RelativeLayout>
    </LinearLayout>
      

Run codeHide result


How it looks like a background: enter image description here

0


source to share


4 answers


EDIT: To set the actual image of the image using a bitmap, not a bitmap:

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("image");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
findViewById(R.id.img2).setImageBitmap(bmp);

      



Gently walking past large images in between activities, it may not show the image in another activity. It is better to save it to internal or external memory and then get it for another activity.

+2


source


get the url of the image and pass it through linking, later in the action you can use the Picasso library to load the screen below, this is the code you can look at.



private void setImageWithPicaso(String imageUrl) {
    if (!(imageUrl == null)) {
        Picasso.with(getActivity()).load(imageUrl).placeholder(R.drawable.placeholder_background).into(imageView, new Callback() {
            @Override
            public void onSuccess() {
                spinner.setVisibility(View.GONE);
            }

            @Override
            public void onError() {
                spinner.setVisibility(View.GONE);
                AppLog.showToastMessage(getActivity(), "Image  loading failed!");

            }
        });
    } else {
        spinner.setVisibility(View.GONE);
        AppLog.showToastMessage(getActivity(), "Image  loading failed!");
    }
}

      

+2


source


Replacement:

findViewById(R.id.img2).setBackgroundDrawable(background);

      

for

findViewById(R.id.img2).setImageDrawable(background);

      

However, the image is placed as a background image. I would like to put an image in my ImageView. Not as a background like the code above.

I think I get where your confusion comes from. Not sure if you fully understand what an ImageView is. Your image is infact in your image, otherwise you will not see it.

0


source


I do not recommend passing image data between activities.

The recommended way is to save it to disk and pass the path to the file between actions.

0


source







All Articles