Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get image from ImageView and set it to other ImageView?

I have two ImageViews as belows :

        <ImageView android:id="@+id/image1"
          android:layout_width="match_parent"  
          android:layout_height="match_parent"  
          android:src="@drawable/ic_launcher" />

        <ImageView android:id="@+id/image2"
          android:layout_width="match_parent"  
          android:layout_height="match_parent"  
          android:adjustViewBounds="true" 
          android:scaleType="fitCenter"
           />

the first imageView displays image in its actual size, the second ImageView should displays image in fitCenter size.

I have been trying this code :

    ImageView img1 = (ImageView) findViewById(R.id.image1);
    ImageView img2 = (ImageView) findViewById(R.id.image2);

    img2.setImageDrawable(img1.getDrawable());

but the second ImageView just displays image as the first one. Yes, in its actual size.

Can anyone help to find the solution?

Thanks

like image 219
vhiefa Avatar asked Mar 24 '15 00:03

vhiefa


People also ask

How to change image in imageview programmatically in Android?

Set different image inside imageview on button click dynamically in android app. Imageview image can be easily replaceable through MainActivity.java coding file because sometimes app developer want to change the imageview image on any button click. So here is the complete step by step tutorial for Change image in imageview programmatically android.

What is the use of imageview in Java?

AnyClass.Application of ImageView is also in applying tints to an image in order to reuse a drawable resource and create overlays on background images. Moreover, ImageView is also used to control the size and movement of an image. Whenever ImageView is added to an activity, it means there is a requirement for an image resource.

How to import image file in imageview?

Select the path of the image file on your computer and click “ OK “. After that set, the “ Qualifier type ” and “ value ” of the image file according to your need and click “ Next ” then “ Import “. Drag the ImageView class in the activity area, a pop-up dialogue box will appear which contains your imported image file.

What is imageview in Android with Kotlin?

ImageView class or android.widget.ImageView inherits the android.view.View class which is the subclass of Kotlin. AnyClass.Application of ImageView is also in applying tints to an image in order to reuse a drawable resource and create overlays on background images. Moreover, ImageView is also used to control the size and movement of an image.


1 Answers

You can try something like this:

ImageView img2 = (ImageView) findViewById(R.id.image2);
img2.setScaleType(ImageView.ScaleType.CENTER_CROP);
img2.setImageDrawable(img1.getDrawable());
like image 140
Prashant Patel Avatar answered Oct 10 '22 02:10

Prashant Patel